El 05/05/2014 22:13, Peter Dimov wrote:
Niall Douglas wrote:
Spurious wakeups absolutely can be prevented by the implementation,
I know.
just for backwards compatibility POSIX cannot do so.
No, the POSIX committee knew that they can be prevented, too.
What I am saying is that they could have disallowed them when they wrote the specification, but did not, on purpose. Code that has problems with spurious wakeups also has problems with other corner cases (such as the one from my other post); and writing it to handle spurious wakeups takes care of these other corner cases as well.
I think spurious wakeups also allow more efficient implementations in some systems or implementations written in user space. When emulating condition variables you can't (or it's extremely expensive) to guarantee that you wake up the waiting thread and that thread can lock the mutex before anyone can lock and modify the predicate. Similar reasons are given in http://en.wikipedia.org/wiki/Spurious_wakeup and http://stackoverflow.com/questions/8594591/why-does-pthread-cond-wait-have-s... Best, Ion