Pthread_mutex_lock.c: 62: __pthread_mutex_lock: statement `mutex & # 8594; __ data .__ owner == 0 'failed

I got this error:

pthread_mutex_lock.c: 62: __pthread_mutex_lock: the statement `mutex → _ data._owner == 0 'failed.

And I can not find a reason. However, I'm not sure about the following code snippet:

Ads:

std::mutex lock; std::condition_variable cond; 

The sequence of locks and unlocks:

 std::unique_lock<std::mutex> lk(lock); cond.wait(lk); lock.unlock(); 

If I delete this sequence, everything will be fine, but without any protection. I am not sure if I use unique_lock .

+6
source share
1 answer

std::unique_lock , and other locks acquire the mutex in the constructor and release it in the destructor. You called lock.unlock() manually in your code, which makes it twice called.

After removing this statement, your code should work correctly.

+2
source

Source: https://habr.com/ru/post/908207/


All Articles