WaitForMultipleEvents

Suspend execution until one-of or all multiple events are signalled.

int WaitForMultipleEvents (int Count, EVENT * arr, int WaitAll, int ms);

Required Header
<process.h>

Return Value

WAIT_FAILED is returned and errno set to the specific reason on failures. WAIT_TIMEOUT is returned if EVENTs were not signalled by the time specified. WAIT_OBJECT_0 + instance is returned if an EVENT was already signalled or was signalled within the time limit specified, where instance is the lowest index of an EVENT in the array that is found to be signalled. In the case of a wait ALL instance will always be 0 if no timeout occured.

Parameters

Count

  The number of EVENTs that are in the array to be tested.

arr

  The EVENT object array-list to wait on.

WaitAll

  Specify non zero to wait until all the EVENTs are signalled before returning.

ms

  The length of time to wait in milliseconds, use INFINITE for no time limit.

Remarks

The WaitForMultipleEvents function suspends execution of the calling thread if an EVENT object is not currently signalled. The thread will wake up if the EVENT is signalled with the SetEvent function, or if the CloseEvent function is called for the EVENTs passed in the parameter array list. The thread will also wake up if the time limit expires before an EVENT is signalled.

The CloseEvent function will release all threads waiting on an EVENT as long as it is not waiting on ALL events. The process will deadlock if you try to close an EVENT object while another thread is waiting on multiple EVENTs, including the one being closed, where the one being closed is not the only EVENT non-signalled in the wait.

Note:
When a Wait-Multiple function call is made for ALL events in a list, the function waits until the signalled state of all EVENTS is set even if some EVENTs have changed state multiple times while waiting.

Process and Threads

See Also    _beginthread, _endthread, _syncthread, CreateEvent, ResetEvent, SetEvent, EventStatus, WaitForSingleEvent, CloseEvent