Boost C++ Libraries: Ticket #5845: mutex.inl: wait_mutex (and its callers) ignore failures from WaitForSingleObject https://svn.boost.org/trac10/ticket/5845 <pre class="wiki">inline int wait_mutex(void* mutex, int time) { unsigned int res = 0; res = WaitForSingleObject(mutex_cast(mutex), time); //:xxx assert(res != WAIT_FAILED &amp;&amp; res != WAIT_ABANDONED); return res; } </pre><p> Its callers are spread across a number of files, including mutex.cpp and recursive_mutex.cpp. Unfortunately, a common use case is shown below (taken from mutex.cpp): </p> <pre class="wiki">void timed_mutex::do_lock() { wait_mutex(m_mutex, INFINITE); } </pre><p> Not only does do_lock() ignore the return value, its callers will proceed to use the guarded data regardless of whether the lock was actually acquired. </p> <p> do_trylock() does a little better, but still ignores return values such as ERROR_INVALID_HANDLE and WAIT_FAILED. </p> <pre class="wiki">bool timed_mutex::do_trylock() { return wait_mutex(m_mutex, 0) == WAIT_OBJECT_0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5845 Trac 1.4.3 Jeffrey Walton <noloader@…> Wed, 31 Aug 2011 00:48:48 GMT component changed; cc, owner set https://svn.boost.org/trac10/ticket/5845#comment:1 https://svn.boost.org/trac10/ticket/5845#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> <p> <code>assert(res == WAIT_OBJECT_0)</code> might be too tight - <code> assert(res == WAIT_OBJECT_0 || res == WAIT_ABANDONED_0)</code> might be a better choice. </p> Ticket viboes Sat, 10 Dec 2011 15:29:02 GMT cc, owner, status, type changed https://svn.boost.org/trac10/ticket/5845#comment:2 https://svn.boost.org/trac10/ticket/5845#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> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Support Requests</span> </li> </ul> <p> Sorry, I don't see any file mutex.inl. Moved to support request until concerned file clarified. </p> Ticket viboes Thu, 29 Dec 2011 10:35:41 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5845#comment:3 https://svn.boost.org/trac10/ticket/5845#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">invalid</span> </li> </ul> <p> Closed as it seems these doesn't corresponds to the current Boost.Thread implementation. </p> Ticket