Quantcast
Channel: GCC C++11 Condition Variable Wait Internals - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Michael Anderson for GCC C++11 Condition Variable Wait Internals

$
0
0

It looks like it is to reorder the destruction of the __lock and __my_lock variables.

The calls should look like this:

construct __my_lock // locks   _M_mutexconstruct __unlock  // unlocks __lockconstruct __my_lock2 // Does nothing as its a move._M_cond.wait(__my_lock2);destroy __mylock2 // unlocks __M_mutexdestroy __unlock // locks __lock againdestroy __mylock // does nothing as its been moved

Without the move the order would be

construct __my_lock // locks   _M_mutexconstruct __unlock  // unlocks __lock_M_cond.wait(__my_lock);destroy __unlock // locks __lockdestroy __mylock // unlocks _M_mutex

Which can result in deadlock as mentioned in the other answer


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>