title: Synchronizing worker threads
body: <p>I have a scenario for which I am trying to come up with the best synchronization approach. We assume that std::thread in C++11 is present, so no need to worry about differences between various threading libraries etc.</p>
  
  <p>The scenario is this. Thread a, the main thread, wants to hand out tasks to a bunch of worker threads. Then, after giving out its final instruction for the time being, it needs to wait for all the threads to complete their work. We don't want to join them, just wait for them to finish their given task. Then thread a has to analyze the collected data from all threads, and then send out commands to the workers to begin the procedure again.</p>
  
  <p>In short, these are the steps.</p>
  
  <ol>
  <li>Thread a sends command x to all worker threads.</li>
  <li>Thread a waits until all the workers have finished.</li>
  <li>Thread a does processing.</li>
  <li>Go back to 1.</li>
  </ol>
  
  <p>What would you suggest that I use? Simple mutexes? Condition variables? A combination of the two? Any tips on how to structure the synchronization to be as efficient as possible would be appreciated.</p>