WaitForMultipleObjects and AutoResetEvents
-
14. února 2012 21:05
I have a WaitForMultipleObjects that waits for all the AutoResetEvents in a vector. I do want the loop that is waiting on these events to be killed, so I have:
while(WaitForMultipleObjects(m_hThreadReadyEvents.size(),&m_hThreadDoneEvents[0],true,500))//is this OK?
{
WaitForSingleObject(hIsKillingMutex,INFINITE);
if (isKilling)
break;
}
The question I have is, if the WaitForMultipleObjects times out because only some of the events have fired, will the events that have fired get Reset? (I'm hoping not....I don't want to make them all manual reset events!)
- Přesunutý Rahul V. Patil 23. května 2012 20:22 API in Windows SDK (From:Parallel Computing in C++ and Native Code)
Všechny reakce
-
23. května 2012 20:38
Hi Idea Hat,
Generically speaking WaitForMultipleObjects (or any wait function) does not consume any signal state from an object it is not reporting.
So, in your specific case, none of the events will be reset if the function returns timeout.
Cheers,
PedroPedroT
- Označen jako odpověď Idea Hat 24. května 2012 15:02
-
24. května 2012 10:27
Well, from the function documentation of WaitForMultipleObjects.
When bWaitAll is TRUE, the function's wait operation is completed only when the states of all objects have been set to signaled. The function does not modify the states of the specified objects until the states of all objects have been set to signaled. For example, a mutex can be signaled, but the thread does not get ownership until the states of the other objects are also set to signaled. In the meantime, some other thread may get ownership of the mutex, thereby setting its state to nonsignaled.
Emphasis mine. So this to me states that any auto reset events are only reset after all events are signaled.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.- Označen jako odpověď Idea Hat 24. května 2012 15:02