views:

74

answers:

2
  • Using WaitForMultipleObjects:
    • Makes it possible, to wait for one or all of specified objects to change to a singled state

Question:

  • How can one wait for a specified amount - such as 5, for example

Usage

dwEvent = WaitForMultipleObjects(
    maxExpectedConnections,
    ghEventsA,
    TRUE,//but wait for a specified number instead
    INFINITE);
A: 

You could just wait several times for a single object each, until you have collected as many "ready" objects as you want.

sth
But waiting on one object blocks the thred. How will you detect if another object becomes signalled?
anon
I meant to still wait on all, but just until one becomes signaled with WaitForMultipleObjects(..., ..., FALSE, ...). Then wait on the remaining objects until the next becomes signaled and so on.
sth
Pretty much the same thing you suggested, in fact.
sth
+2  A: 

Use the waitall flag to indicate that you want the wait to return when any object is signalled. When wait returns, remove the signalled object from the array of objects and wait again until you have N (e.g. 5 in your case) signalled objects.

anon
Hi Neil, "waitall" flag - is this a predefined directive?
Aaron
I meant pass FALSE in the bWaitAll parameter
anon