Boost C++ Libraries: Ticket #5843: thread.cpp: thread::join() does not throw for a non-joinable thread https://svn.boost.org/trac10/ticket/5843 <p> Boost uses non-joinable threads. For example, under Windows: </p> <pre class="wiki">thread::thread() : m_joinable(false) { m_thread = reinterpret_cast&lt;void*&gt;(GetCurrentThread()); m_id = GetCurrentThreadId(); } </pre><p> The thread::join() properly asserts the property, but still attempts to join a non-joinable thread: </p> <pre class="wiki">void thread::join() { assert(m_joinable); //See race condition comment below int res = 0; res = WaitForSingleObject(reinterpret_cast&lt;HANDLE&gt;(m_thread), INFINITE); assert(res == WAIT_OBJECT_0); res = CloseHandle(reinterpret_cast&lt;HANDLE&gt;(m_thread)); assert(res); // This isn't a race condition since any race that could occur would // have us in undefined behavior territory any way. m_joinable = false; } </pre><p> Related to <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/5838"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/5838</a> and <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/5842"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/5842</a>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5843 Trac 1.4.3 Jeffrey Walton <noloader@…> Wed, 31 Aug 2011 00:47:17 GMT component changed; owner set https://svn.boost.org/trac10/ticket/5843#comment:1 https://svn.boost.org/trac10/ticket/5843#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Anthony Williams</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> </ul> <p> <code>assert(res == WAIT_OBJECT_0)</code> might be too tight - <code> assert(res == WAIT_OBJECT_0 || res == WAIT_ABANDONED_0)</code> might be a better choice. </p> Ticket viboes Fri, 02 Dec 2011 23:22:31 GMT cc set https://svn.boost.org/trac10/ticket/5843#comment:2 https://svn.boost.org/trac10/ticket/5843#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> </ul> <p> I don't know IIUC the interface, but IMO, a thread that has already finished can not be joined. Do you agree with my understanding? </p> <p> Preconditions: </p> <blockquote> <p> this-&gt;get_id()!=boost::this_thread::get_id() </p> </blockquote> <p> Effects: </p> <blockquote> <p> If *this refers to a thread of execution, waits for that thread of execution to complete. </p> </blockquote> <p> Postconditions: </p> <blockquote> <p> If *this refers to a thread of execution on entry, that thread of execution has completed. *this no longer refers to any thread of execution. </p> </blockquote> <p> Throws: </p> <blockquote> <p> boost::thread_interrupted if the current thread of execution is interrupted. </p> </blockquote> <p> Notes: </p> <blockquote> <p> join() is one of the predefined interruption points. </p> </blockquote> <p> </p> Ticket viboes Sun, 04 Dec 2011 15:59:36 GMT owner, status changed; cc deleted https://svn.boost.org/trac10/ticket/5843#comment:3 https://svn.boost.org/trac10/ticket/5843#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> removed </li> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Wed, 07 Dec 2011 00:15:56 GMT type changed; cc set https://svn.boost.org/trac10/ticket/5843#comment:4 https://svn.boost.org/trac10/ticket/5843#comment:4 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Support Requests</span> </li> </ul> <p> Moved to support until the resolution is clarified. </p> Ticket viboes Wed, 14 Dec 2011 21:36:33 GMT status, type changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/5843#comment:5 https://svn.boost.org/trac10/ticket/5843#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Support Requests</span> → <span class="trac-field-new">Bugs</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> Ticket