Behavior of WaitForMultipleObjects when multiple handles signal at the same time

后端 未结 4 953
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 09:24

Given: I fill up an array of handles with auto reset events and pass it off to WaitForMultipleObjects with bWaitAll = FALSE.

From MSDN: “When bWaitAll is FALSE, th

4条回答
  •  余生分开走
    2021-01-13 09:56

    Yes. One alternative would be that you could do WaitForSingleObject(handle, 0) on each handle which will return immediately and indicate if they are signaled or not.

    EDIT: Here's sample pseudocode for what I mean:

    ret = WaitForMultipleObjects()
    if (ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + (count))
    {
        firstSignaled = ret - WAIT_OBJECT_0;
    
        // handles[firstSignaled] guaranteed signalled!!
    
        for (i = firstSignaled + 1; i < count; i++)
        {
            if (WaitForSingleObject(handles[i], 0) == WAIT_OBJECT_0)
            {
               // handles[i] Signaled!
            }
        }
    }
    

提交回复
热议问题