lost-wakeup
consider two processes A and B:
- A checks condition
- B satisfies condition, wakes up A
- A goes to sleep (because it already checked the condition before)
and so is a form of TOCTOU
a way to solve it is
set a "wakeup waiting" bit which tracks the time a process is in the state between 2 and 3
when a wakeup is sent to a process, set this bit
when a process tries to sleep, if the bit is set, clear it and do not go to sleep
consumer process clears this bit on every loop iteration (i.e., when done processing an event)
however, the waking process needs to know which process is going to be woken up when setting the bit
additionally, a wakeup waiting bit (WW bit) intended for an earlier wait can prevent a later sleep
- A is waiting for event 1 on channel
chan; sleeps because event is not there yet
- A is waiting for event 1 on channel
- B wakes up A, A's WW bit is set
- A handles event 1, clears A's WW bit
- A is now waiting for event 2 on channel
chan; sleeps because event is not there yet (and A's WW bit is not set)
- A is now waiting for event 2 on channel
refs
Page Links
No links