Re: pthread_cond_wait spurious wakeup

Konstantin Belousov <[email protected]> Sat, 25 Jul 2026 23:05:11 +0300
Newsgroups gmane.os.freebsd.devel.hackers
Message-ID <[email protected]>
On Sat, Jul 25, 2026 at 02:06:31PM +0300, Dmitry Morozovsky wrote:
> 
> On 25.07.2026 2:41, Konstantin Belousov wrote:
> > On Sat, Jul 25, 2026 at 02:02:35AM +0300, Slawa Olhovchenkov wrote:
> > > Is pthread_cond_wait susceptible to spurious wakeup in FreeBSD? The
> > > pthread_cond_wait man page doesn't say anything about waiting thread
> > > can unblocking in cases like EINTR. But in
> > > lib/libthr/thread/thr_cond.c:232-249,
> > > I seem to see a successful return from pthread_cond_wait on EINTR
> > > case. So, we don't have a spurious wakeup issue, or does the man page
> > > need to be corrected and an additional predicate should be used in
> > > conjunction with pthread_cond_wait?
> > Spurious wakeups are allowed and can happen.  They are not neccessarly
> > limited to signals delivery.
> > 
> > 'The additional predicate' is how the user code must be structured anyway,
> > because pthread_cond_wait() drops the mutex that is supposed to protect
> > the data holding the condition.
> 
> So, is the wording
> 
> "The waiting thread unblocks only after..."
> 
> from the manpage wrong (incomplete)?
> 
> And, if yes, how do you think should it be rephrased/corrected?

https://reviews.freebsd.org/D58458