pthread_mutex_lock.c:62: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed
10,768
std::unique_lock
and the other locks acquire a mutex in constructor and releases it in destructor.
You called lock.unlock()
in your code manually, making it being called effectively twice.
After removing that statement your code should work properly.
Author by
Dejwi
Updated on June 28, 2022Comments
-
Dejwi almost 2 years
I received that error:
pthread_mutex_lock.c:62: __pthread_mutex_lock: Assertion `mutex->_data._owner == 0' failed.
And I cannot found any cause of that. However I'm not sure about the following piece of code:
Declarations:
std::mutex lock; std::condition_variable cond;
Sequence of locks & unlocks:
std::unique_lock<std::mutex> lk(lock); cond.wait(lk); lock.unlock();
If I remove this sequence - everything works fine, but without any protection. I'm not sure if I use
unique_lock
properly. -
Mike Seymour about 12 yearsAlternatively, call
lk.unlock()
, so the lock knows that the mutex has been unlocked. (And perhaps call the mutex something other than "lock", so you don't confuse it with a lock).