Boost C++ Libraries: Ticket #5502: race condition between shared_mutex timed_lock and lock_shared https://svn.boost.org/trac10/ticket/5502 <p> There is a potential race condition between 3 threads. Thread 1 - has a shared lock Thread 2 - goes into a timed_lock loop with a small sleep Thread 3 - tries shared_lock </p> <p> Expected behavior: Thread 3 gets the lock when thread 2 fails to get exclusive lock. </p> <p> What happens: based on timing, there can be a race condition causing a hang unless Thread 1 releases the lock. </p> <p> Test and patch for boost-trunk that fixes the problem for me attached. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5502 Trac 1.4.3 eliothorowitz@… Mon, 25 Apr 2011 18:05:45 GMT attachment set https://svn.boost.org/trac10/ticket/5502 https://svn.boost.org/trac10/ticket/5502 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> Ticket eliothorowitz@… Mon, 25 Apr 2011 18:06:36 GMT attachment set https://svn.boost.org/trac10/ticket/5502 https://svn.boost.org/trac10/ticket/5502 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">patch.5502</span> </li> </ul> Ticket anonymous Sun, 17 Jul 2011 00:49:56 GMT <link>https://svn.boost.org/trac10/ticket/5502#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5502#comment:1</guid> <description> <p> any update on this? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 20 Dec 2011 21:31:29 GMT</pubDate> <title>cc, owner, type, status, milestone changed https://svn.boost.org/trac10/ticket/5502#comment:2 https://svn.boost.org/trac10/ticket/5502#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>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</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">To Be Determined</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> <p> I have tested your patch and it works. Yes the issue is that when </p> <pre class="wiki"> state.exclusive_waiting_blocked=false; </pre><p> the shared_cond variable must be notified also. </p> <p> I have committed this at <a class="changeset" href="https://svn.boost.org/trac10/changeset/76084" title="Thread: Notify shread_cond when state.exclusive_waiting_blocked=false ...">[76084]</a>. To be closed when merged to release. </p> <p> Thanks for catching this and, of course, for the solution. </p> Ticket viboes Sat, 07 Jan 2012 20:53:02 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5502#comment:3 https://svn.boost.org/trac10/ticket/5502#comment:3 <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/76346" title="Thread: merge from trunk to fix #6141, #5594, #5040 and #5502.">[76346]</a>) Thread: merge from trunk to fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6141" title="#6141: Bugs: Compilation error when boost.thread and boost.move are used together (closed: fixed)">#6141</a>, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5594" title="#5594: Bugs: boost::shared_mutex not fully compatible with Windows CE. (closed: fixed)">#5594</a>, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5040" title="#5040: Bugs: future.hpp in boost::thread does not compile with /clr (closed: fixed)">#5040</a> and <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5502" title="#5502: Patches: race condition between shared_mutex timed_lock and lock_shared (closed: fixed)">#5502</a>. </p> Ticket