title: C++ std condition variable covering a lot of share variables
body: <p>I am writing a multithreaded program in C++ and in my main thread I am waiting for my other threads to put packages in different queues. Depending on the sort of package and from which thread they originate.</p>
  
  <p>The queues are protected by mutexes as it should be.</p>
  
  <p>But in my main I don't want to be doing:</p>
  
  <pre><code>while(true)
  if(!queue1-&gt;empty)
  {
       do stuff
  }
  if(!queue2-&gt;empty)
  {
       do stuff
  }
  etc
  </code></pre>
  
  <p>So you need to use condition variables to signal the main that something has changed. Now I can only block on 1 condition variable so I need all these threads to use the same conditional variable and an accompanying mutex. Now I dont want to really use this mutex to lock all my threads. It doesn't mean that when 1 thread is writing to a queue, another cant write to a totally different queue. So I use seperate mutexes for each queue. But now how do I use this additional mutex that comes with the conditional variable.</p>
  
  <p>How it's done with 2 threads and 1 queue using boost, very simular to std.
  <a href="http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html" rel="nofollow">http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html</a> :</p>
  
  <pre><code>template&lt;typename Data&gt;
  class concurrent_queue
  {
      private:
      boost::condition_variable the_condition_variable;  
      public:
      void wait_for_data()
      {
          boost::mutex::scoped_lock lock(the_mutex);
          while(the_queue.empty())
          {
               the_condition_variable.wait(lock);
          }
      }
      void push(Data const&amp; data)
      {
           boost::mutex::scoped_lock lock(the_mutex);
           bool const was_empty=the_queue.empty();
           the_queue.push(data);
           if(was_empty)
           {
               the_condition_variable.notify_one();
           }
       }
       // rest as before
   };
  </code></pre>
  
  <p>So how do you solve this?</p>