@Mikra,

There is an error in your code. You have to acquire the lock before waiting on 
a condition variable, or the behavior is undefined.

* * *

@see:

[http://en.cppreference.com/w/cpp/thread/condition_variable/wait](http://en.cppreference.com/w/cpp/thread/condition_variable/wait)

"Calling this function if lock.mutex() is not locked by the current thread is 
undefined behavior. "

[http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_wait.html](http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_wait.html)

"The pthread_cond_wait() and pthread_cond_timedwait() functions are used to 
block on a condition variable. They are called with mutex locked by the calling 
thread or undefined behaviour will result."

[https://msdn.microsoft.com/en-us/library/windows/desktop/ms682052(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682052\(v=vs.85\).aspx)

The Windows implementation doesn't explicitly state the behavior, but all the 
examples have a call to 'EnterCriticalSection(&CritSection);' before they wait 
on the condition. 

Reply via email to