title: waitformultipleobjects with unknown number of handles
body: <p>This is what I need to do - 
  1. Define a handle threadHandle and define an array of handles h[20]...where each entry in the array has value threadHandle.</p>
  
  <ol>
  <li>My code opens up 20 threads and once done, each thread has to signal the main thread and once all of them signal, the main thread has to log something to a log file.</li>
  </ol>
  
  <p>I plan to do something like:</p>
  
  <p>define threadHandle and the array of handles h[20} defined above.</p>
  
  <p>Obnce the code opens 20 threads, do - <code>waitformultipleobjects(NULL,20,h,true,10000)</code></p>
  
  <p>Now the code will wait for the all the handles in the h array to be set before the wait returns. But since all the values of h are the same, the wait function returns an error. Is there a way to go around this? I basically need all the threads to signal back to the calling thread...defining 20 handlers for each of the 20 threads doesnt seem to be a good idea either.</p>
  
  <p>Can I do something like this instead? - </p>
  
  <p>define threadHandle and the array of handles h[20].
  Maintain a variable count for the number of threads that signaled back to the main thread.</p>
  
  <pre><code>waitforsingleobject(threadHandle)
  </code></pre>
  
  <p>once this returns, increment count and if count &lt; 20 repeat the above wait statement.
  Keep doing it till count  = 20 and then log to file.
  Of course, in between if any of the waits timesout, then we log a failure to the log file.</p>
  
  <p>I am trying this out, but was wondering if there is a better way to do this.</p>
  
  <p>TIA.
  anand</p>