I have 3 different threads that use the Windows SetEvent
API to set an event each.
DWORD thFunc1(LPVOID)
{
...
SetEvent(event1);
...
}
DWORD thFunc2(LPVOID)
{
...
SetEvent(event2);
...
}
DWORD thFunc3(LPVOID)
{
...
SetEvent(event3);
...
}
A 4th thread is waiting on all of these events using WaitForMultipleObjects
API.
DWORD thCatch(LPVOID)
{
...
DWORD ret = WaitForMultipleObjects(3, arrHandles, FALSE, INFINITE);
...
}
My question is twofold:
Any inputs would be appreciated.
The WaitForMultipleObjects
API call makes a single promise when more than one object entered the signaled state:
If multiple objects become signaled, the function returns the index of the first handle in the array whose object was signaled.
The order in which multiple objects are signaled cannot be determined from the WaitForMultipleObjects
call.
If the order in which events happened is important, you will have to record that information elsewhere. You could use a singly linked list with atomic push and pop operations, and signal an event when a new entry arrived.