title: Thread safety for STL queue
body: <p>I am using a queue to communicate between threads. I have one reader and multiple writer threads. My question is do I need to lock the queue every time when I use push/front/pop from the queue for the reader? Can I do something like the following:</p>
  
  <pre><code>//reader threads
  getLock();
  get the number of elements from the queue
  releaseLock();
  
  int i = 0;
  while( i &lt; numOfElements){
      queue.front();
      queue.pop();
      i++
  }
  </code></pre>
  
  <p>The idea is that I want to reduce the granularity of the locked code and since the writer thread would only write to the back of the queue and there is only a single reader thread. As long as I get the number of elements, then I could get the elements from the queue OR do I need to enclose the <code>front()</code> and <code>pop()</code> in the lock as well?</p>