Boost C++ Libraries: Ticket #12620: Make boost::unique_lock::unlock respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED https://svn.boost.org/trac10/ticket/12620 <p> For a C++11 conformant g++ with working C++11 threads, the following code works if LIB is defined to std and throws if defined to boost:: </p> <pre class="wiki">#define LIB boost LIB::mutex mtx; LIB::unique_lock&lt;LIB::mutex&gt; l(mtx, LIB::defer_lock); LIB::condition_variable cnd; cnd.wait(l, []{ /*whatever*/ return true;}); // this throws. </pre><p> The attached patch makes boost::unique_lock::unlock respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED and not require the lock to be held (if you'll ever have only one thread waiting on a condition variable it seems that the mutex is useless as there's no race involved, c++11 threads at least when backed by pthread seems to follow that behavior). </p> <p> Even with this patch, boost *will* lock the mutex on exit - I didn't attempt to change that (as my code copes with that), but c++11 seems to avoid touching the mutex or correctly leaves it as it once was. </p> <p> I'm not sure what/if any of this behavior is standardized or implementation dependent, but it seems more coherent to respect BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED - specially the common case where it's not defined. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12620 Trac 1.4.3 Alexandre Pereira Nunes <alexandre.nunes@…> Wed, 23 Nov 2016 20:48:20 GMT attachment set https://svn.boost.org/trac10/ticket/12620 https://svn.boost.org/trac10/ticket/12620 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">lock_types.patch</span> </li> </ul> Ticket viboes Fri, 30 Dec 2016 01:39:04 GMT owner, description changed https://svn.boost.org/trac10/ticket/12620#comment:1 https://svn.boost.org/trac10/ticket/12620#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>description</strong> modified (<a href="/trac10/ticket/12620?action=diff&amp;version=1">diff</a>) </li> </ul> Ticket viboes Fri, 30 Dec 2016 01:48:30 GMT type, severity changed https://svn.boost.org/trac10/ticket/12620#comment:2 https://svn.boost.org/trac10/ticket/12620#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Support Requests</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Not Applicable</span> </li> </ul> <p> The implementation corresponds to the documentation and I believe to the standard library as well (<a class="ext-link" href="http://en.cppreference.com/w/cpp/thread/unique_lock/unlock"><span class="icon">​</span>http://en.cppreference.com/w/cpp/thread/unique_lock/unlock</a>). </p> Ticket viboes Tue, 03 Jan 2017 06:50:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12620#comment:3 https://svn.boost.org/trac10/ticket/12620#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> Ticket