|From:||Brent W. Baccala|
|Subject:||Re: race condition destroying condition variables|
|Date:||Tue, 19 Dec 2017 14:20:40 -0500|
Brent W. Baccala, on mar. 19 déc. 2017 00:08:44 -0500, wrote:
> Looks like there's a race condition when we destroy a condition variable. My
> understanding of the expected behavior is that once all the threads have been
> signaled (i.e, pthread_cond_broadcast is called), the condition variable can be
> safely destroyed with pthread_cond_destroy.
Err, I don't think that POSIX allows to assume that. The fact that
pthread_cond_broadcast has returned doesn't mean that other threads have
finished with pthread_cond_wait.
(A) pthread_cond_broadcast(&ep->notbusy); pthread_mutex_unlock(&lp->lm); (B) pthread_cond_destroy(&rp->notbusy);...accompanied by the following comment:
Besides, the threads should also all go through reacquiring the associated
mutex, usually sitting right next to the condition variable, and usually
both embedded in a parent object. What you're normally really interested
in is releasing this parent object, including destroying the mutex, which
means you also have to wait for all threads to unlock it. One common way
to deal with this is reference counters on the parent object.
|[Prev in Thread]||Current Thread||[Next in Thread]|