title: thread safe with pop and visit in c++ queue
body: <p>I know std::queue is not thread safe, but I don't want to lock queue.
  so I use pop &amp; push limit on usages.</p>
  
  <p>for instance, 
  when I want to pop:
  I have an enum to express first element status</p>
  
  <pre><code>enum {
      Busy = 1,
      Unused,
  }
  </code></pre>
  
  <p>when I add an elment to queue:</p>
  
  <pre><code>void UserAdd() {
      lock.lock();
      element.status = BUSY;
      queue.push_back(element);
      lock.unlock();
  }
  </code></pre>
  
  <p>when I visit :</p>
  
  <pre><code>//only visit function, and every element only called once.
  void UserVisit() {
      auto header = queue.front();
      .......
      queue.front().status = UNUSED;
      return ;
  }
  </code></pre>
  
  <p>I judge first elements status when I want to pop element.</p>
  
  <p>If first element is Busy, wait;</p>
  
  <p>If first element is Unused, pop;</p>
  
  <pre><code>void UserPop() {
      while (queue.front().status != Unused) {
          usleep(200);
      }
      lock.lock();
      queue.pop();
      lock.unlock();
  }
  </code></pre>
  
  <p>thread A: 1. UserAdd, 2. UserVisit, 1.UserAdd, 2.UserVisit loop ...</p>
  
  <p>thread B: 1. UserPop.</p>
  
  <p>Is UserPop() &amp;&amp; UserVisit thread safe ?.</p>
  
  <p>I think It's thread safe.</p>