title: blocking queue using c++ std queue
body: <p>I'm trying to implement a blocking queue with limited size, for one provider and multiple consumers. it is working well when the consumer is sleep()ing for 1 second, but hangs when there is no sleep.
  what am I doing wrong?</p>
  
  <p>here is my code:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;unistd.h&gt;
      #include &lt;thread&gt;
      #include &lt;queue&gt;
      #include &lt;mutex&gt;
      #include &lt;condition_variable&gt;
  
      using namespace std;
      template &lt;class T&gt; class BlockingQueue: public queue&lt;T&gt; {
          public:
              BlockingQueue() {
                  queue&lt;T&gt;();
              }
  
              BlockingQueue(int size) {
                  maxSize = size;
                  queue&lt;T&gt;();
              }
  
              void push(T item) {
                  unique_lock&lt;std::mutex&gt; wlck(writerMutex);
                  while(Full())
                      isFull.wait(wlck);
                  queue&lt;T&gt;::push(item);
                  if(notEmpty()) 
                      isEmpty.notify_one();
              }
  
              bool notEmpty() {
                  return !queue&lt;T&gt;::empty();
              }
  
              bool Full(){
                  return queue&lt;T&gt;::size() &gt;= maxSize;
              }
  
          T pop() {
              unique_lock&lt;std::mutex&gt; lck(readerMutex);
  
              popMutex.lock();    
              while(queue&lt;T&gt;::empty()) {
                  isEmpty.wait(lck);
              }
              T value = queue&lt;T&gt;::front();
              queue&lt;T&gt;::pop();
              if(!Full())
                  isFull.notify_all();
              popMutex.unlock();
              return value;
          }
  
          private:
              int maxSize;
              std::mutex readerMutex;
              std::mutex popMutex;
              std::mutex writerMutex;
              condition_variable isFull;
              condition_variable isEmpty;
      };
      void runProvider(BlockingQueue&lt;int&gt;* Q) {
          int number=0;
          while(1) {
              Q-&gt;push(number);
              cout&lt;&lt;"provide "&lt;&lt;number&lt;&lt;endl;
              number++;
          }
      }
  
      void runConsumer(int n,BlockingQueue&lt;int&gt;* Q) {
          int number;
          while(1) {
              number = Q-&gt;pop();
              cout&lt;&lt;"consume#"&lt;&lt;n&lt;&lt;": "&lt;&lt;number&lt;&lt;endl;
          }
      }
  
      int main(int argc, char** argv) {
          BlockingQueue&lt;int&gt; *Queue = new BlockingQueue&lt;int&gt;(10);
          cout&lt;&lt;"starting provider"&lt;&lt;endl;
          std:thread provider(runProvider, Queue);
          sleep(1);
  
          cout&lt;&lt;"starting consumer"&lt;&lt;endl;
          std::thread consumer1(runConsumer, 1,Queue);
          std::thread consumer2(runConsumer, 2,Queue);
  
          provider.join();
          delete(Queue);
          return 0;
      }
  </code></pre>