gpt4 book ai didi

windows - 等待事件是否会受到虚假唤醒的影响?

转载 作者:可可西里 更新时间:2023-11-01 13:54:31 26 4
gpt4 key购买 nike

SleepConditionVariableCS 的 MSDN 页面指出

Condition variables are subject to spurious wakeups (those not associated with an explicit wake) and stolen wakeups (another thread manages to run before the woken thread). Therefore, you should recheck a predicate (typically in a while loop) after a sleep operation returns.

因此,条件等待必须包含在 while 循环中,即

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

如果我使用 events我可以在等待 ( WaitForSingleObject ) 事件信号时取消 while 循环而不是条件变量吗?

最佳答案

对于 WaitForSingleObject(),没有虚假唤醒,因此您可以消除循环。

如果您将 WaitForMultipleObjectsEx()bAlertable=TRUE 一起使用,将 MsgWaitForMultipleObjects() 与唤醒掩码一起使用,或者 MsgWaitForMultipleObjectsEx() 使用 bAlertable=TRUE 或唤醒掩码,然后等待可以在事件实际发出信号之前在其他条件下结束。

关于windows - 等待事件是否会受到虚假唤醒的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38757420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com