gpt4 book ai didi

c++ - WaitForSingleObject 等待超时

转载 作者:行者123 更新时间:2023-11-28 08:02:14 29 4
gpt4 key购买 nike

我正在使用 waitForAll 参数 = true 的 WaitForMultipleObject 函数。这里使用一个 std::vector 的 handle 对象来等待。如果这个函数超时了,那么如何识别等待哪个句柄超时??。

if(WAIT_OBJECT != WaitForMultipleObject(vector.size(), vector.data(), true, 16000))
{
//get the event that causes the wait to time out(assume that only one object is timed out.others are successfully set.)
}

最佳答案

根据 MSDN 的 WaitForMultipleObjects函数定义:

Return value minus WAIT_OBJECT_0 indicates the array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects.

因此,您只需要检查:函数是否成功 - 一切正常,如果没有,则检查数组中有哪些句柄,哪些没有。因此,您可以找出有问题的句柄。

此外,我建议您查看 SignalObjectAndWait功能。它的行为是不同的,但也许您会发现它在某些情况下很有用。

关于c++ - WaitForSingleObject 等待超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11115581/

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