Boost C++ Libraries: Ticket #2361: thread_specific_ptr: nature of the key, complexity and rationale https://svn.boost.org/trac10/ticket/2361 <p> I didn't know that the key of thread_specific_ptr was the address of the variable. I expected a constant complexity for boost::thread_specific_ptr, but if the key is the address this seams not possible. I supose you had some good raison to not use an index key instead of the address. </p> <p> Please, could you add the nature of the key, the complexity of the boost::thread_specific_ptr and the rationale on the design choice on the documentation. </p> <p> Ticket requested by A. W. on <a class="ext-link" href="http://www.nabble.com/-thread--TSS-cleanup-to19590361.html#a19623640"><span class="icon">​</span>http://www.nabble.com/-thread--TSS-cleanup-to19590361.html#a19623640</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2361 Trac 1.4.3 Andrey Semashev Fri, 18 Sep 2009 20:30:11 GMT attachment set https://svn.boost.org/trac10/ticket/2361 https://svn.boost.org/trac10/ticket/2361 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">tss.patch</span> </li> </ul> <p> The patch restores constant-time complexity of thread_specific_ptr </p> Ticket Andrey Semashev Fri, 18 Sep 2009 20:41:09 GMT <link>https://svn.boost.org/trac10/ticket/2361#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:1</guid> <description> <p> FWIW, I attached the patch against branches/release that restores constant-time complexity of thread_specific_ptr, instead of linear on the number of pointers. This essentially restores the behavior that was there in previous Boost versions (1.33, for sure). The patch also fixes a couple of other issues: calling cleanup function on NULL pointers and releasing cleanup function on pointer destruction. </p> <p> I ran tests on Linux (GCC 4.3) and Windows (MSVC 9) with this patch and it looked fine. </p> <p> Anthony, I know you're working in a different direction in trunk, thus I realise that this patch is unlikely to be applied to the mainline. However, I'd like to encourage you to provide constant-time complexity of TSS, like it was before Boost.Thread rewrite. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Fri, 18 Sep 2009 20:50:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:2</guid> <description> <p> 2 Vicente: I'm not in position to give official response to your questions, but I suspect that the approach Anthony took could simplify solving problems with dynamically loadable/unloadable modules (nonetheless, the current branches/release version does not behave correctly with respect to this). </p> <p> For the record, my patch does suffer from this problem, too. However, I believe it is possible to provide both constant-time complexity and proper modules support. If not, well... I'd opt for performance. Perhaps, a library option should be provided to make everyone happy. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 20 Nov 2009 12:25:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:3</guid> <description> <p> Anthony, I see that you have modified the thread_specific_ptr implementation, but I don't see yet any explanation about the complexity and the rational in the documentation&gt; Please could you respond to this ticket? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 05 Dec 2011 18:55:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2361#comment:1" title="Comment 1">andysem</a>: </p> <blockquote class="citation"> <p> FWIW, I attached the patch against branches/release that restores constant-time complexity of thread_specific_ptr, instead of linear on the number of pointers. This essentially restores the behavior that was there in previous Boost versions (1.33, for sure). The patch also fixes a couple of other issues: calling cleanup function on NULL pointers and releasing cleanup function on pointer destruction. </p> <p> I ran tests on Linux (GCC 4.3) and Windows (MSVC 9) with this patch and it looked fine. </p> <p> Anthony, I know you're working in a different direction in trunk, thus I realise that this patch is unlikely to be applied to the mainline. However, I'd like to encourage you to provide constant-time complexity of TSS, like it was before Boost.Thread rewrite. </p> </blockquote> <p> Andrey, </p> <p> I don't know if you maintain this patch on your local system in synchronization with trunk. If this is the case could you attach it. I would like to play with to consider if your approach can be modified to take in account also modules support. </p> <p> Thanks </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Mon, 05 Dec 2011 19:17:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:5</guid> <description> <p> I'm sorry, I don't maintain the patch. I prepared it once for the Boost release I'd been working with at the time. I didn't look at the current code of thread_specific_ptr but I think it shouldn't be too hard to adapt it to the current code base. You can contact me (either in this ticket or in any other way) if you need any help on this patch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 07 Jan 2012 23:41:05 GMT</pubDate> <title>owner, status, milestone changed https://svn.boost.org/trac10/ticket/2361#comment:6 https://svn.boost.org/trac10/ticket/2361#comment:6 <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> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Sat, 25 Aug 2012 12:24:50 GMT milestone changed https://svn.boost.org/trac10/ticket/2361#comment:7 https://svn.boost.org/trac10/ticket/2361#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.52.0</span> </li> </ul> <p> Next follows the text that will be added </p> <pre class="wiki">[heading Rational about the nature of the key] Boost.Thread uses the address of the `thread_specific_ptr` instance as key of the thread specific pointers. This avoids to create/destroy a key which will need a lock to protect from race conditions. This has a little performance liability, as the access must be done using an associative container. </pre> Ticket viboes Sat, 25 Aug 2012 12:29:33 GMT <link>https://svn.boost.org/trac10/ticket/2361#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:8</guid> <description> <p> 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> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 25 Aug 2012 12:42:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:9</guid> <description> <p> That should be Rationale, not Rational, right? </p> <p> Also, are there plans to change the implementation to avoid associative container lookup? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 26 Aug 2012 15:32:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2361#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2361#comment:10</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2361#comment:9" title="Comment 9">anonymous</a>: </p> <blockquote class="citation"> <p> That should be Rationale, not Rational, right? </p> </blockquote> <p> I will fix it. </p> <blockquote class="citation"> <p> Also, are there plans to change the implementation to avoid associative container lookup? </p> </blockquote> <p> Not for the next releases. Changing to a random access container needs much more reflexion. I will see what can be done in a middle future. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 13 Sep 2012 19:11:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2361#comment:11 https://svn.boost.org/trac10/ticket/2361#comment:11 <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">fixed</span> </li> </ul> <p> Committed revision 80516. </p> Ticket