Boost C++ Libraries: Ticket #2681: lwm_pthread fails to catch initialization error https://svn.boost.org/trac10/ticket/2681 <p> pthread_mutex_init() return value is not checked and if the mutex creation fails, the next pthread_mutex_lock() call result is undefined on some platforms. </p> <p> I think that it would be appropriate to throw an exception from the lightweight_mutex constructor if pthread_mutex_init fails. </p> <p> The problem is in </p> <p> boost/detail/lwm_pthreads.hpp </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2681 Trac 1.4.3 Olivier Langlois <olivier.langlois@…> Tue, 27 Jan 2009 15:32:31 GMT cc set https://svn.boost.org/trac10/ticket/2681#comment:1 https://svn.boost.org/trac10/ticket/2681#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">olivier.langlois@…</span> added </li> </ul> <p> I can give more details on how I stumbled on the problem. I had this bad statement in my code which had the intent of reseting boost::shared_ptr </p> <p> <em> reset shared pointer my_ptr = boost::shared_ptr&lt;<a class="missing wiki">MyClass</a>&gt;(static_cast&lt;<a class="missing wiki">MyClass</a> *&gt;(NULL)); </em></p> <p> So for each 'reset', a new ref counter with its mutex was created. After few thousands of 'reset', pthread_mutex_init() eventually returned ENOMEM which was not catched by boost as described in the initial description. </p> <p> and finally on the next pthread_mutex_lock with the unitialized mutex, on my OS (CentOS 4), the program just block inside the call and never return. </p> Ticket Jonathan Wakely <jwakely.boost@…> Fri, 05 Jun 2009 16:57:10 GMT cc, owner, component changed https://svn.boost.org/trac10/ticket/2681#comment:2 https://svn.boost.org/trac10/ticket/2681#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">jwakely.boost@…</span> added </li> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">Peter Dimov</span> </li> <li><strong>component</strong> <span class="trac-field-old">threads</span> → <span class="trac-field-new">smart_ptr</span> </li> </ul> <p> I think lwm_pthreads.hpp belongs to the smart_ptr component not threads. </p> <p> Boost.Threads asserts that the pthread calls succeed, e.g. </p> <pre class="wiki"> BOOST_VERIFY( !pthread_mutex_init(&amp;m_, 0) ); </pre><p> but I don't know if lightweight_mutex wants to avoid that overhead. </p> Ticket Peter Dimov Thu, 26 Nov 2009 20:55:06 GMT <link>https://svn.boost.org/trac10/ticket/2681#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2681#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/57953" title="Add error checking to lwm_pthreads.hpp. Refs #2681.">[57953]</a>) Add error checking to lwm_pthreads.hpp. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2681" title="#2681: Bugs: lwm_pthread fails to catch initialization error (closed: fixed)">#2681</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 26 Nov 2009 22:18:44 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/2681#comment:4 https://svn.boost.org/trac10/ticket/2681#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Peter Dimov Mon, 30 Nov 2009 20:25:03 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2681#comment:5 https://svn.boost.org/trac10/ticket/2681#comment:5 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/58065" title="Merge [57953] to release. Fixes #2681.">[58065]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/57953" title="Add error checking to lwm_pthreads.hpp. Refs #2681.">[57953]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2681" title="#2681: Bugs: lwm_pthread fails to catch initialization error (closed: fixed)">#2681</a>. </p> Ticket