signal( )
to wake one thread as a broadcast( )
to wake all of them, thus breaking any possibly expected 1:1 relationship between signals and wakeup. If there are ten threads waiting, only one will win and the other nine will experience spurious wakeup.
To allow for implementation flexibility in dealing with error conditions and races inside the operating system, condition variables may also be allowed to return from a wait even if not signed, though it is not clear how many implementations actually do that. In the Solaris implementation of condition variables, a spurious wakeup may occur without the condition being assigned if the process is signal; the wait system call aborts and returns Inter
.
The Linux p-thread implementation of condition variables guarantees it will not do that.
Because spurious wakeup can happen whenever there's a race and possibly even in the absence of a race or a signal, when a thread wakes on a condition variable, it should always check that the condition it sought is satisfied. If it is not, it should go back to sleeping on the condition variable, waiting for another opportunity.
References
{{DEFAULTSORT:Spurious Wakeup C POSIX library Threads (computing)