Boost C++ Libraries: Ticket #3837: thread_specific_ptr returns incorrect values if another one was constructed at the same address earlier https://svn.boost.org/trac10/ticket/3837 <p> optional&lt; thread_specific_ptr&lt;int&gt; &gt; optr; </p> <p> void other_thread(){ </p> <blockquote> <p> optr=none; </p> </blockquote> <blockquote> <p> optr=in_place(); </p> </blockquote> <p> } </p> <p> int main(){ </p> <blockquote> <p> optr=in_place(); </p> </blockquote> <blockquote> <p> optr-&gt;reset(new int); </p> </blockquote> <blockquote> <p> thread(bind(&amp;other_thread)); </p> </blockquote> <blockquote> <p> this_thread::sleep(posix_time::seconds(5)); </p> </blockquote> <blockquote> <p> assert(optr-&gt;get() == 0); <em>fails! </em></p> </blockquote> <p> } </p> <p> the assertion should not fail. </p> <p> this can also be triggered by dynamic allocation. the address of thread_specific_ptr is treated as a key that is unique until the end of the thread in Boost.Thread, which is an incorrect assumption. a unique key obtained under a mutex on construction of thread_specific_ptr could be used instead. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3837 Trac 1.4.3 anonymous Mon, 15 Feb 2010 23:36:53 GMT <link>https://svn.boost.org/trac10/ticket/3837#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3837#comment:1</guid> <description> <p> More serious problems may arise if a thread_specific_ptr&lt;X&gt; and a thread_specific_ptr&lt;Y&gt; occupy the same address at different times. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 11 Jun 2010 07:51:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3837#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3837#comment:2</guid> <description> <p> Why the assertion should not fail? You are using a global variable optr ion the two threads. The following interleaving seems possible </p> <blockquote> <p> optr=in_place(); optr-&gt;reset(new int); <em> main optr=none; optr=in_place(); </em> other_thread assert(optr-&gt;get() == 0); <em></em> main succeed </p> </blockquote> <p> As the global variable has been re-assigned with in_place(). Am I missing something? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 19 Jun 2010 19:53:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3837#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3837#comment:3</guid> <description> <p> the assertion should not fail because the global ts-ptr has been reconstructed, so it's ptr should be 0 in each thread. but it does fail, try it. </p> <p> the current ts-ptr cant handle different ts-ptrs at the same address at different points in time. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Anthony Williams</dc:creator> <pubDate>Thu, 28 Oct 2010 10:30:43 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/3837#comment:4 https://svn.boost.org/trac10/ticket/3837#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sun, 11 Dec 2011 16:40:31 GMT keywords set https://svn.boost.org/trac10/ticket/3837#comment:5 https://svn.boost.org/trac10/ticket/3837#comment:5 <ul> <li><strong>keywords</strong> tss added </li> </ul> Ticket viboes Mon, 28 May 2012 16:45:04 GMT milestone changed https://svn.boost.org/trac10/ticket/3837#comment:6 https://svn.boost.org/trac10/ticket/3837#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.42.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Sat, 18 Aug 2012 17:38:33 GMT <link>https://svn.boost.org/trac10/ticket/3837#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3837#comment:7</guid> <description> <p> If I understand correctly, you are expecting that the destructor of the thread_specific_ptr must reset the thread specific pointer for all the threads that are using this key. </p> <p> IMO, the user must ensure that the thread_specific_pointer instance outlives all the threads that are using it. Otherwise, the library needs to maintain a list of all the threads that are using a specific key, which goes against the purpose of tss to reduce the contention between threads by accessing a thread specific and not a global data. </p> <p> The documentation must state clearly this constraint (design principle). Note that pthread works already in this way. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 19 Aug 2012 15:29:31 GMT</pubDate> <title>owner, status changed; milestone deleted https://svn.boost.org/trac10/ticket/3837#comment:8 https://svn.boost.org/trac10/ticket/3837#comment:8 <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">assigned</span> → <span class="trac-field-new">new</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> Ticket viboes Tue, 21 Aug 2012 05:39:17 GMT status changed https://svn.boost.org/trac10/ticket/3837#comment:9 https://svn.boost.org/trac10/ticket/3837#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sat, 25 Aug 2012 12:31:30 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3837#comment:10 https://svn.boost.org/trac10/ticket/3837#comment:10 <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">invalid</span> </li> </ul> <p> Doc updated accordingly. Committed in trunk at revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/80198" title="Thread: update tss doc to take care of #2361 and #3837">[80198]</a>. </p> Ticket