title: Exception thrown: Read access violation when calling method front
body: <p>When i try to take the first item from the queue, i have error.</p>
  <blockquote>
  <p>Exception thrown: Read access violation.
  ** std :: deque &lt;int, std :: allocator &gt; :: front ** (...) returned 0xDDDDDDE9.</p>
  </blockquote>
  <p>At the time of the error, the queue is not empty</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;thread&gt;
  #include&lt;mutex&gt;
  #include&lt;chrono&gt;
  using namespace std;
  int total;
  queue&lt;int&gt; ox;
  mutex mtx, mtx1;
  void push(int x) {
     mtx1.lock();
     ox.push(x);
     mtx1.unlock();
  }
  bool pop(int x) {
     if (ox.size() == 0) this_thread::sleep_for(chrono::milliseconds(1));
     if (ox.size() != 0) {
        mtx.lock();
        x = ox.front();
        ox.pop();
        mtx.unlock();
        return true;
     }
     if (ox.size() == 0) {
        return false;
     }
     return false;
  }
  void producer() {
     for (int i = 0; i &lt; 1024 * 1024 * 4; i++) push(1);
  }
  void consumer() {
  
     int sum = 0;
     for (int i = 0; i &lt; 1024 * 1024 * 4; i++) {
        int k;
        if (pop(k)) sum += k;
     }
     total += sum;
  
  }
  
  int main()
  {
    thread th1(producer);
    thread th2(consumer);
    th1.join();
    th2.join();
    cout &lt;&lt; total;
  }
  </code></pre>