In monitors, if a thread A goes to wait as some condition is false and if other thread B signals as condition is true and resets the condition so condition becomes false again. When thread A resumes execution should it check the condition? or should it proceed after that?
Asked
Active
Viewed 41 times
0
-
It depends on what you want. If you want thread A to stop if thread B resets the event, then make your code do that. What you're asking is very unclear. A code sample with a more detailed explanation would be helpful. – Jim Mischel Oct 16 '13 at 18:40
1 Answers
0
In most programming languages/environments your approach is wrong, because it does not take into account of spurious wakeups.
When waiting on a condition, in many languages/environments have to consider the possibility that you will be woken up without anybody explicitly sending you a signal. This is called spurious wakeup (see e.g. Do spurious wakeups actually happen?).
If the signaling thread resets the condition, you cannot distinguish between a proprer signal and a spurious one, so you should not do that.