Re: pthread_cond_wait spurious wakeup

Konstantin Belousov <[email protected]> Sat, 25 Jul 2026 02:41:49 +0300
Newsgroups gmane.os.freebsd.devel.hackers
Message-ID <[email protected]>
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.