<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1033: thread::join() effects?</title>
<meta property="og:title" content="Issue 1033: thread::join() effects?">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1033.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="1033"><a href="lwg-defects.html#1033">1033</a>. <code>thread::join()</code> effects?</h3>
<p><b>Section:</b> 32.4.3.6 <a href="https://wg21.link/thread.thread.member">[thread.thread.member]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Alberto Ganesh Barbati <b>Opened:</b> 2009-03-12 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#thread.thread.member">issues</a> in [thread.thread.member].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>

<p>
While looking at <code>thread::join()</code> I think I spotted a couple of
possible defects in the specifications. I could not find a previous
issue or NB comment about that, but I might have missed it.
</p>

<p>
The postconditions clause for <code>thread::join()</code> is:
</p>

<blockquote><p>
<i>Postconditions:</i> If <code>join()</code> throws an exception, the value
returned by <code>get_id()</code> is unchanged. Otherwise, <code>get_id() == id()</code>.
</p></blockquote>

<p>
and the throws clause is:
</p>

<blockquote><p>
<i>Throws:</i> <code>std::system_error</code> when the postconditions cannot be achieved.
</p></blockquote>

<p>
Now... how could the postconditions <em>not</em> be achieved?
It's just a matter of resetting the value of <code>get_id()</code> or leave it
unchanged! I bet we can always do that. Moreover, it's a chicken-and-egg
problem: in order to decide whether to throw or not I depend on the
postconditions, but the postconditions are different in the two cases.
</p>

<p>
I believe the throws clause should be:
</p>

<blockquote><p>
<i>Throws:</i> <code>std::system_error</code> when the effects or postconditions
cannot be achieved.
</p></blockquote>

<p>
as it is in <code>detach()</code>, or, even better, as the postcondition is
trivially satisfiable and to remove the circular dependency:
</p>


<blockquote><p>
<i>Throws:</i> <code>std::system_error</code> if the effects cannot be achieved.
</p></blockquote>

<p>
Problem is that... ehm... <code>join()</code> has no "Effects" clause. Is that intentional?
</p>

<p><i>[
See the thread starting at c++std-lib-23204 for more discussion.
]</i></p>


<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
Pete believes there may be some more general language (in frontmatter)
that can address this and related issues such as <a href="lwg-defects.html#962" title="Various threading bugs #12 (Status: C++11)">962</a><sup><a href="https://cplusplus.github.io/LWG/issue962" title="Latest snapshot">(i)</a></sup>.
</p>
<p>
Move to Open.
</p>
</blockquote>

<p><i>[
2009-11-18 Anthony provides wording.
]</i></p>



<p><i>[
2010-02-12 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>


<p id="res-1033"><b>Proposed resolution:</b></p>
<p>
Edit 32.4.3.6 <a href="https://wg21.link/thread.thread.member">[thread.thread.member]</a> as indicated:
</p>

<blockquote><pre>
void join();
</pre>
<blockquote>
<p>
5 <i>Precondition:</i> <code>joinable()</code> is <code>true</code>.
</p>
<p><ins>
<i>Effects:</i> Blocks until the thread represented by <code>*this</code> has completed.
</ins></p>

<p>
6 <i>Synchronization:</i> The completion of the thread represented by
<code>*this</code> happens before (6.10.2 <a href="https://wg21.link/intro.multithread">[intro.multithread]</a>)
<code>join()</code> returns. [<i>Note:</i> Operations on <code>*this</code> are not
synchronized. &mdash; <i>end note</i>]
</p>

<p>
7 <i>Postconditions:</i> <del>If <code>join()</code> throws an exception, the value
returned by <code>get_id()</code> is unchanged. Otherwise,</del> <ins>The thread
represented by <code>*this</code> has completed.</ins> <code>get_id() == id()</code>.
</p>

<p>
8 ...
</p>


</blockquote>
</blockquote>






</body>
</html>
