Boost C++ Libraries: Ticket #5836: tss.cpp: tss_data_dec_use suffers a race condition https://svn.boost.org/trac10/ticket/5836 <p> It appears the reference counting of tss_data_use suffers a race condition. Perhaps it would be best to use an interlocked decrement on tss_data_use: </p> <pre class="wiki">void tss_data_dec_use(boost::mutex::scoped_lock&amp; lk) { if (0 == --tss_data_use) { tss_data_cleanup_handlers_type::size_type i; for (i = 0; i &lt; tss_data_cleanup_handlers-&gt;size(); ++i) { delete (*tss_data_cleanup_handlers)[i]; } delete tss_data_cleanup_handlers; tss_data_cleanup_handlers = 0; lk.unlock(); delete tss_data_mutex; tss_data_mutex = 0; #if defined(BOOST_HAS_WINTHREADS) TlsFree(tss_data_native_key); #elif defined(BOOST_HAS_PTHREADS) pthread_key_delete(tss_data_native_key); #elif defined(BOOST_HAS_MPTASKS) // Don't know what to put here. // But MPTASKS isn't currently maintained anyways... #endif } } </pre><p> In addition, it appears code built with BOOST_HAS_MPTASKS will fail in unexpected ways. Perhaps it would be a good idea to create a compile time failure to save users: </p> <p> Index: tss.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/thread/src/tss.cpp,v retrieving revision 1.20 diff -<a class="changeset" href="https://svn.boost.org/trac10/changeset/1" title="Import core sources for SVNmanger 0.38 ">r1</a>.20 tss.cpp 67a68 </p> <blockquote class="citation"> <blockquote> <p> #error "MPTASKS isn't currently maintained" </p> </blockquote> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5836 Trac 1.4.3 Jeffrey Walton <noloader@…> Wed, 31 Aug 2011 00:42:54 GMT component changed; cc, owner set https://svn.boost.org/trac10/ticket/5836#comment:1 https://svn.boost.org/trac10/ticket/5836#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">noloader@…</span> added </li> <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> Ticket viboes Fri, 02 Dec 2011 23:26:12 GMT cc, owner, status changed https://svn.boost.org/trac10/ticket/5836#comment:2 https://svn.boost.org/trac10/ticket/5836#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </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> <p> Isn't it protected by the lock given as parameter? </p> Ticket viboes Wed, 07 Dec 2011 00:41:07 GMT type changed https://svn.boost.org/trac10/ticket/5836#comment:3 https://svn.boost.org/trac10/ticket/5836#comment:3 <ul> <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 request until resolution clarified. </p> Ticket viboes Tue, 20 Dec 2011 17:22:42 GMT status, type changed; resolution set https://svn.boost.org/trac10/ticket/5836#comment:4 https://svn.boost.org/trac10/ticket/5836#comment:4 <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> </ul> <p> IMO, it is protected by the lock given as parameter. </p> <p> Please, reopen it if you don't agree with the resolution. </p> Ticket