Boost C++ Libraries: Ticket #7496: [thread] call interrupt() and join() int destructor of a joinable thread https://svn.boost.org/trac10/ticket/7496 <p> boost::thread's destructor calls terminate if joinable, in order to conform to C++11 specification. I am not sure if this is the best course of action. My understanding -- form the C++ Committee papers and informal presentations -- is that the reason for introducing a 'terminating destructor' was the lack of thread cancellation/interruption functionality. Thread interruption is supposed to be the preferred behavior for thread's destructor. std::thread does not support interruption (for some reasons), but boost::thread does (this is already a departure from C++11), so shouldn't the latter prefer to interrupt and join a joinable thread in the destructor? </p> <p> My preference would be to join (rater than detach) after the interruption. If I remember correctly, the argument against joining for std::thread is that there would be an unexpected hang upon reaching the end of the scope. The argument against detaching for std::thread is that the detached thread may be holding references to automatic variables defined in the scope of the forking thread that we are now exiting. </p> <p> I believe that with thread interruption in place the argument against joining is mitigated, while the argument against detaching still holds. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7496 Trac 1.4.3 viboes Sat, 13 Oct 2012 13:44:26 GMT owner, status changed https://svn.boost.org/trac10/ticket/7496#comment:1 https://svn.boost.org/trac10/ticket/7496#comment:1 <ul> <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 Sun, 28 Oct 2012 19:19:24 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7496#comment:2 https://svn.boost.org/trac10/ticket/7496#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> After discussion on the ML (<a class="ext-link" href="http://boost.2283326.n4.nabble.com/thread-terminating-destructor-tt4636872.html"><span class="icon">​</span>http://boost.2283326.n4.nabble.com/thread-terminating-destructor-tt4636872.html</a>) it seems that this request is more needed. </p> <p> I've created a ticket that should help the user to get what they need at destruction </p> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7541" title="#7541: Feature Requests: Add a thread wrapper class that joins on destruction (closed: fixed)">#7541</a> Add a thread wrapper class that joins on destruction </p> <p> Note that the resolution will be to parameterize the action to be done at destruction so that the user can easily do a interrupt and join. </p> Ticket