加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 正在等待虚假唤醒的事件?

发布时间:2020-12-14 04:00:31 所属栏目:Windows 来源:网络整理
导读: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 shoul
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(),没有虚假的唤醒,所以你可以消除循环.

如果使用带有bAlertable = TRUE的WaitForMultipleObjectsEx(),带有唤醒掩码的MsgWaitForMultipleObjects()或带有bAlertable = TRUE的MsgWaitForMultipleObjectsEx()或唤醒掩码,则等待可以在事件实际发出信号之前以其他条件结束.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读