title: Using a single Condition Variable to pause multiple threads
body: <p>I have a program that starts N number of threads (async/future). I want the main thread to set up some data, then all threads should go while the main thread waits for all of the other threads to finish, and then this needs to loop.</p>
  
  <p>What I have atm is something like this </p>
  
  <pre><code>int main()
  {  
      //Start N new threads (std::future/std::async)
      while(condition)
      {
         //Set Up Data Here
         //Send Data to threads
         {
             std::lock_guard&lt;std::mutex&gt; lock(mrun);
             bRun = true;
  
         }
         run.notify_all();
         //Wait for threads
         {
             std::unique_lock&lt;std::mutex&gt; lock(mrun);
             run.wait(lock, [] {return bDone; });
         }
         //Reset bools
         bRun = false;
         bDone = false;
      }
      //Get results from futures once complete
  }
  
  int thread()
  {
      while(otherCondition)
      {
         std::unique_lock&lt;std::mutex&gt; lock(mrun);
         run.wait(lock, [] {return bRun; });
         bDone = true;
         //Do thread stuff here
         lock.unlock();
         run.notify_all();
      }
  }
  </code></pre>
  
  <p>But I can't see any signs of either the main or the other threads waiting for each other! Any idea what I am doing wrong or how I can do this?</p>