title: Boost synchronization
body: <p>I have NUM_THREADS threads, with the following codes in my thread:</p>
  
  <pre><code>/*
  Calculate some_value;
  */
  
  //Critical section to accummulate all thresholds
  {
      boost::mutex::scoped_lock lock(write_mutex);
      T += some_value;
      num_threads++;
      if (num_threads == NUM_THREADS){
          T = T/NUM_THREADS;
          READY = true;
          cond.notify_all();
          num_threads = 0;
      }
  }
  
  //Wait for average threshold to be ready
  if (!READY)
  {
      boost::unique_lock&lt;boost::mutex&gt; lock(wait_mutex);
      while (!READY){
          cond.wait(lock);
      }
  }
  //End critical section
  
  /*
  do_something;
  */
  </code></pre>
  
  <p>Basically, I want all the threads to wait for the READY signal before continuing. num_thread is set to 0, and READY is false before threads are created. Once in a while, deadlock occurs. Can anyone help please?
  All the boost variables are globally declared  as follows:</p>
  
  <pre><code>boost::mutex write_mutex;
  boost::mutex wait_mutex;
  boost::condition cond;
  </code></pre>