As you know, variable conditions must be called in a loop to avoid false awakenings. Like this:
while (not condition) condvar.wait();
If another thread wants to wake up the waiting thread, it must set the condition flag to true. For instance:.
condition = true; condvar.notify_one();
I wonder if it is possible for the condition variable to be blocked by this scenario:
1) The waiting thread checks the status flag and finds that it is FALSE, so it will introduce the condvar.wait() procedure.
2) But before that (but after checking the status flag) the waiting thread is unloaded by the kernel (for example, due to the expiration of the time interval).
3) At this time, another thread wants to notify the pending thread of the status. It sets the condition flag to TRUE and calls condvar.notify_one();
4) When the kernel manager starts the first thread again, it enters the condvar.wait() procedure, but the notification has already been skipped.
Thus, the waiting thread cannot exit condvar.wait() , even though the status flag is set to TRUE because there are no more wake-up notifications.
Is it possible?
source share