title: Using more than one mutex with a conditional variable
body: <p>Is there a mechanism to have a conditional variable use multiple mutexes?
  I am in Linux and pthreads in C++.</p>
  
  <p>In an application, I need two mutexes (instead of one) to be atomically acquired and released by pthread_cond_wait(), but the function only accepts one.</p>
  
  <p>I have a class named BlockingManager and it has the method:</p>
  
  <pre><code>blockMeFor( pthread_cond_t* my_cond, pthread_mutex_t* my_lock, set&lt;int&gt; waitees);
  </code></pre>
  
  <p>and I am using it, assuming that it acquires/releases the mutex just like pthread_cond_wait.</p>
  
  <p>The problem is that for implementing blockingManager I need an internal mutex too and both of these mutexes should be acquired and released atomically.</p>
  
  <p>There is a somehow related discussion here, it says waiting for more than one mutex yields undefined behavior.
  <a href="http://sourceware.org/ml/libc-help/2011-04/msg00011.html" rel="nofollow">http://sourceware.org/ml/libc-help/2011-04/msg00011.html</a></p>
  
  <p>A producer/consumer model for the problem I am facing follows:</p>
  
  <p>We have multiple clients.
  Each client has some tasks.
  Each task probably has multiple prerequisites (either among the tasks of the same client or other clients).
  Each client has one consumer thread.
  The tasks are assigned to the clients from one producer thread.
  The newly assigned task may be eligible to be done before the previous tasks.
  There may be no task to be done at some moments, but if there is a task to be done, at least one should be done. (It should be work-conserving)</p>
  
  <p>I am using one condvar per consumer thread and it would block once there is no task to be done for that thread.
  The condvar may be signaled by either</p>
  
  <ul>
  <li><p>The producer thread assigning a new task.</p></li>
  <li><p>Another consumer thread finishing a task.</p></li>
  </ul>
  
  <p>I am using one mutex per consumer to protect the shared data-structures between producer &amp; consumer.
  And one mutex (internal mutex) to protect the shared data-structures between multiple-consumers.</p>