title: Wait for one of several threads to finish?
body: <p>I am implementing a thread pool. The work required by each thread is 1-10 seconds of CPU, so I'm happy to have a traditional thread pool with workers, or I'm happy to spawn a new thread for each unit of work. It doesn't matter.</p>
  
  <p>I would like to have some way for the master control thread to know when one of the N worker threads finishes its work and is ready for more (or its time to start another). I've looked at pthread_join and pthread_cond_wait. There doesn't seem to be a way to wait for one of N. So I thought about having the master thread have a variable that it uses to go to sleep and having the workers wake it up. This seems to work if the workers don't die. However, if they die, there's a window between the time that the worker wakes up the controller and the time it dies which I don't want to deal with.</p>
  
  <p>I've looked at Intel's TBB but it looks much more complicated than I need.</p>
  
  <p>Is there a simple equivalent in PTHREADS to WaitForMultipleObjects in Microsoft Windows?</p>