[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: race condition destroying condition variables

From: Richard Braun
Subject: Re: race condition destroying condition variables
Date: Tue, 19 Dec 2017 10:17:10 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Dec 19, 2017 at 09:25:16AM +0100, Samuel Thibault wrote:
> 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.

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.

Richard Braun

reply via email to

[Prev in Thread] Current Thread [Next in Thread]