gpt4 book ai didi

c++ - waitforsingleobject 等待一个已经发出信号的事件

转载 作者:行者123 更新时间:2023-11-30 00:37:05 26 4
gpt4 key购买 nike

我做 WaitForSingleObject(handle, timeout);如果在调用 WaitForSingleObject 之前 handle 已经发出信号,函数将返回什么?

我认为它应该立即返回一个 WAIT_OBJECT_0...但在我的例子中,它等待事件被设置并且因为这没有发生(事件已经设置),它会计时出。

请指教。

最佳答案

取决于事件。您对手动重置事件的期望是正确的,而自动重置事件不会保持信号状态:Event Objects (Windows) .

Auto-reset event An event object whose state remains signaled until a single waiting thread is released, at which time the system automatically sets the state to nonsignaled.

If no threads are waiting, the event object's state remains signaled. If more than one thread is waiting, a waiting thread is selected. Do not assume a first-in, first-out (FIFO) order. External events such as kernel-mode APCs can change the wait order.

关于c++ - waitforsingleobject 等待一个已经发出信号的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14275497/

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