Boost C++ Libraries: Ticket #7334: Fix bug concerning condition_variable_any reported in [c++std-lib-32966] https://svn.boost.org/trac10/ticket/7334 <p> the following is ok: </p> <pre class="wiki"> Thread A Thread B ... lk.lock() ... cv.wait(lk) lk.lock() ... cv.notify_one() ... cv.~condition_variable_any() ... lk.unlock() ... ... finally exits cv.wait // ok, not a data race </pre><p> Below is a complete C++11 <a class="missing wiki">HelloWorld</a> that is a simple translation of the example in the POSIX pthread_cond_destroy spec. It should run and not crash or assert: </p> <pre class="wiki">#include &lt;list&gt; #include &lt;mutex&gt; #include &lt;condition_variable&gt; #include &lt;functional&gt; #include &lt;thread&gt; #include &lt;chrono&gt; #include &lt;cassert&gt; template &lt;class T&gt; class locked_list { std::mutex mut_; std::list&lt;T&gt; list_; public: typedef typename std::list&lt;T&gt;::iterator iterator; typedef typename T::key key; template &lt;class ...Args&gt; void emplace_back(Args&amp;&amp; ...args) {list_.emplace_back(std::forward&lt;Args&gt;(args)...);} iterator find(const key&amp; k) { std::unique_lock&lt;std::mutex&gt; lk(mut_); while (true) { iterator ep = std::find(list_.begin(), list_.end(), k); if (ep == list_.end()) return ep; if (!ep-&gt;busy()) { ep-&gt;set_busy(); return ep; } ep-&gt;wait(lk); } } void erase(iterator i) { std::lock_guard&lt;std::mutex&gt; _(mut_); assert(i-&gt;busy()); i-&gt;notify_all(); list_.erase(i); } iterator end() {return list_.end();} }; template &lt;class Key&gt; class elt { Key key_; std::condition_variable_any notbusy_; bool busy_; public: typedef Key key; explicit elt(const Key&amp; k) : key_(k), busy_(false) {} bool busy() const {return busy_;} void set_busy() {busy_ = true;} void unset_busy() {busy_ = false;} template &lt;class Lock&gt; void wait(Lock&amp; lk) {notbusy_.wait(lk);} void notify_all() {notbusy_.notify_all();} bool operator==(const Key&amp; k) const {return key_ == k;} }; void f1(locked_list&lt;elt&lt;int&gt;&gt;&amp; list) { auto i = list.find(1); assert(i != list.end()); std::this_thread::sleep_for(std::chrono::milliseconds(500)); list.erase(i); } void f2(locked_list&lt;elt&lt;int&gt;&gt;&amp; list) { auto i = list.find(1); assert(i == list.end()); } int main() { locked_list&lt;elt&lt;int&gt;&gt; list; list.emplace_back(1); std::thread t1 = std::thread(f1, std::ref(list)); std::this_thread::sleep_for(std::chrono::milliseconds(250)); std::thread t2 = std::thread(f2, std::ref(list)); t1.join(); t2.join(); } </pre><p> If we substitute in boost::condition_variable_any for std::condition_variable_any for the notbusy_ data member of class elt, we get: </p> <pre class="wiki">Assertion failed: (!pthread_mutex_unlock(m)), function ~interruption_checker, file /Users/hhinnant/Development/boost-dev/boost-trunk/boost/thread/pthread/thread_data.hpp, line 171. Abort trap: 6 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7334 Trac 1.4.3 viboes Sat, 08 Sep 2012 21:08:49 GMT status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/7334#comment:1 https://svn.boost.org/trac10/ticket/7334#comment:1 <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">duplicate</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> <p> Duplicated of <a class="assigned ticket" href="https://svn.boost.org/trac10/ticket/7319" title="#7319: Bugs: Take care of c++std-lib-32966 issue (assigned)">#7319</a>. </p> Ticket