
9 Oct
2006
9 Oct
'06
6:25 p.m.
Peter Dimov wrote: [...]
Another possible fix is to broadcast() (signal() is not enough).
while (!pred()) { if (!timed_wait(lock, xt)) return broadcast(), false; }
Ummmm.... why is signal() not enough?
Threads A and B waiting (A does timed wait), C changes something, signals and enters wait expecting another state change followed by signaling from either A or B (whichever gets the signal and makes processing). If A times out and only re-signal, that signal can be consumed by C as spurious wake. So broadcast() is needed to wake B and let it do the job. regards, alexander.