title: How to test my blocking queue actually blocks
body: <p>I have a blocking queue (it would be really hard for me to change its implementation), and I want to test that it actually blocks. In particular, the <code>pop</code> methods must block if the queue is empty and unblock as soon as a <code>push</code> is performed. See the following pseudo C++11 code for the test:</p>
  
  <pre><code>BlockingQueue queue; // empty queue
  
  thread pushThread([] 
  { 
      sleep(large_delay);
      queue.push(); 
  });
  
  queue.pop();
  </code></pre>
  
  <p>Obviously it is not perfect, because it may happen that the whole thread <code>pushThread</code> is executed and terminates before <code>pop</code> is called, even if the delay is large, and the larger the delay the more I have to wait for the test being over.</p>
  
  <p>How can I properly ensure that <code>pop</code> is executed before <code>push</code> is called and that is blocks until <code>push</code> returns?</p>