Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does WaitForMultipleObjects() reset all auto-reset events?

I've got an event loop that's waiting on several auto-reset events. The events were all initialized into array eventHandles_ with CreateEvent(NULL, false, false, NULL).

while (true)
{
    DWORD waitResult = WaitForMultipleObjects(3, eventHandles_, false, INFINITE);
    switch (waitResult)
    {
    case WAIT_OBJECT_0 + 0:
        //handle event...

    case WAIT_OBJECT_0 + 1:
        //handle event...

    case WAIT_OBJECT_0 + 2:
        //handle event...
    }
}

My question: if event 1 and 2 occur simultaneously, the loop will process WAIT_OBJECT_0 + 1 because it's first. But will event 2 remain signaled when the loop comes around again? Or does it get reset automatically?

like image 394
japreiss Avatar asked Mar 19 '12 19:03

japreiss


1 Answers

"...modification occurs only for the object or objects whose signaled state caused the function to return..."

http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx

And from the mouth of one Raymond Chen:

If waiting for one event, then only that event is modified. If waiting for all events, then all are modified. That's what the documentation means by "object or objects". Singular if wait-any, plural if wait-all.

like image 68
Steve Johnson Avatar answered Nov 01 '22 14:11

Steve Johnson