When using WaitForMultipleObjects(... /*bWaitAll=*/FALSE ...)
function will obviously change the state of the first synchronization object, which will make it return. That is, if you have (have) the signal auto-reset event , and the return value indicates that this event object called the function to return, it certainly was reset.
However, consider the case when you have several objects - here:
If bWaitAll
is FALSE
, this function checks the handles in the array starting at index 0 until one of the objects is signaled. If several objects become signals, the function returns the index of the first handle in the array whose object was signaled.
So, you will only get the first descriptor, and you don’t know if any events were noted after this index.
For objects whose state is changed, now the question is: If several objects were specified at the moment of WaitForMultipleObjects return, will only the state of the first one be changed, or all objects with an alarm be reset?
The documents indicate:
The function changes the state of some types of synchronization objects. Modification occurs only for the object or objects, the signaling state caused a return of the function.
therefore, this may indicate that it is indeed possible for several objects to change their state. However, this is slightly contrary to the statement:
... this function checks the handles in the array starting at index 0 until one of the objects is signaled ....
And, in addition, this will mean that this function cannot be used with several synchronization objects (for example, with an automatic reset event, semaphores, etc.) that change their state because you always lose information.
I found expression in this answer to "Behavior of WaitForMultipleObjects when several descriptors ..." that others would conclude this (from a comment there):
WaitForMultipleObjects () checks the array of descriptors from 0 to and returns as soon as it finds a signal descriptor. Only this first reset handle was detected for an unauthorized state; others are untouched. - user82238 / # 259 at 19:27
but I would like to repeat and explicitly confirm this explicitly.
There is also an interesting discussion at CodeGuru that does not seem to shed any light on this.