Reputation: 361
pthread_cond_wait()
is woken by pthread_cond_signal()
when I receive certain response. But in some cases, I do not get a response. So in those cases, when I simply destroy the pthread_mutex_t
, pthread_cond_t
it seems to be still continuing in an infinite loop.
I do not understand if this is the reason or anything else. Please help me.
Upvotes: 0
Views: 423
Reputation: 1001
The behavior of pthread_cond_wait()
is undefined when its mutex is destroyed.
More than that, pthread_cond_wait()
should be called when its associated mutex is locked,
otherwise the functions' behavior is also undefined.
The function also establishes a dynamic bind between the mutex and the condition variable (when the function returns, the bind is released too). Therefore destroying the condition variable also may lead to undefined behavior.
More details can be found here: opengroup: pthread_cond_wait
Upvotes: 3