Is the event awaiting fake awakenings?

The MSDN page for SleepConditionVariableCS indicates that

Variable conditions are subject to false awakenings (not associated with a clear trace) and stolen awakenings (another thread manages to run up to the swollen thread). Therefore, you should double-check the predicate (usually in a while loop) after the sleep operation returns.

As a result, the conditional wait should be enclosed in a while loop, i.e.

while (check_predicate())
{
    SleepConditionVariableCS(...)
}

If I used events instead of condition variables, can I end the while loop while waiting ( WaitForSingleObject ) to report the event?

+4
source share
1

WaitForSingleObject() , .

WaitForMultipleObjectsEx() bAlertable=TRUE, MsgWaitForMultipleObjects() MsgWaitForMultipleObjectsEx() bAlertable=TRUE , , .

+7

Source: https://habr.com/ru/post/1650105/


All Articles