Re: WaitForMultipleObjects: How to asynchronously wait?
On 11 Feb., 16:16, "Daneel" <michael.ransb...@gmail.com> wrote:
Return value of WaitForMultipleObjects tells you which handle caused it
to return. You now need to prepare a new HANDLE[] array containing only
the two remaining handles, and call WaitForMultipleObjects again with
just these two handles.
Cheers! I'm now using:
for (i = 0; i < 6; i++) {
dwEvent = WaitForMultipleObjects(6-i, h, FALSE, INFINITE); //
IMPORTANT: NUMBER OF OBJECTS TO WAIT FOR
for (j = dwEvent; j < 6; j++) {
h[dwEvent] = h[dwEvent+1];
}
// ...
}
That seems to work fine :-).
I think I was too quick with my response. With the above code,
WaitForMultipleObjects will return -1, usually after 3-4 of the 6
threads are finished. If I set bWaitAll to TRUE, i.e., dwEvent =
WaitForMultipleObjects(6, h, TRUE, INFINITE), then it works all the
time (all threads execute and WaitForMultipleObjects returns after the
last thread finishes).
Does anyone know why this happens?
Many thanks,
Michael