#651005 /usr/share/man/man3/pthread_cond_wait.3.gz: pthread_cond_wait documentation incorrect, does not allow for spurious wakeups

Package:
glibc-doc
Source:
glibc
Submitter:
Nikolaus Rath
Date:
2025-01-10 09:27:02 UTC
Severity:
normal
Tags:
#651005#5
Date:
2011-12-04 23:33:35 UTC
From:
To:
pthread_cond_wait(3) says:

       pthread_cond_wait atomically unlocks the mutex (as per
       pthread_unlock_mutex)  and  waits  for the  condition  variable
       cond to be signaled. The thread execution is suspended and does
       not consume any CPU time until the condition variable is
       signaled. The mutex must  be  locked  by the  calling thread on
       entrance to pthread_cond_wait. Before returning to the calling
       thread, pthread_cond_wait re-acquires mutex (as per
       pthread_lock_mutex).

This is actually not true in practice, and also not required by POSIX.
pthread_cond_wait() sometimes wakes up without the condition variable
having been signaled, and POSIX allows for such "spurious wakeups".

See also

http://en.wikipedia.org/wiki/Spurious_wakeup
http://stackoverflow.com/questions/8378789/forcing-a-thread-context-switch

Suggested patch:

       pthread_cond_wait atomically unlocks the mutex (as per
       pthread_unlock_mutex) and waits for the  condition  variable
       cond to be signaled. The thread execution is suspended and does
       not consume any CPU time until woken up. The thread will be woken
       up when the condition variable is signaled, but spurious wakeups
       without a corresponding signal may also happen. The mutex must
       be  locked  by the  calling thread on entrance to
       pthread_cond_wait. Before returning to the calling thread,
       pthread_cond_wait re-acquires mutex (as per pthread_lock_mutex).

#651005#10
Date:
2025-01-09 22:19:53 UTC
From:
To:
control: reassign -1 651005 manpages-dev

Hi,

The pthread_cond_wait(3) manpage got moved to the manpages-dev package,
I am therefore reassigning the bug accordingly.

Regards
Aurelien