I came across this interesting paragraph in the Boost thread documentation today:
void wait(boost::unique_lock<boost::mutex>& lock)
...
Effects: Atomically call lock.unlock() and blocks the current thread. The thread will unblock when notified by a call to this->notify_one() or this->notify_all(), or spuriously. When the thread is unblocked (for whatever reason), the lock is reacquired by invoking lock.lock() before the call to wait returns. The lock is also reacquired by invoking lock.lock() if the function exits with an exception.
So what I am interested in is the meaning of the word "spuriously". Why would the thread be unblocked for spurious reasons? What can be done to resolve this?
This article by Anthony Williams is particularly detailed.
He also points out that you shouldn't use the
timed_wait
overloads that take a duration, and you should generally use the versions that take a predicateThis article by Vladimir Prus is also interesting.
This blog post gives a reason for Linux, in terms of the
futex
system call returning when a signal is delivered to a process. Unfortunately it doesn't explain anything else (and indeed is asking for more information).The Wikipedia entry on spurious wakeups (which appear to be a posix-wide concept, btw, not limited to boost) may interest you too.