title: Multi-Threaded accessing same deque C++
body: <p>In my multi-threaded application, I have two threads that use the same <code>std::deque</code>. One of them writes to it, while the other reads from it (for data analysis). </p>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Deque iterator not dereferencable</p>
  </blockquote>
  
  <p><strong>EDIT:</strong>
  This is the code that I use for reading from the deque. The error is thrown somewhere deeper in the if-condition (where I'm accessing the deque with <code>at</code>).</p>
  
  <pre><code>for (int i = 0; i &lt;myDeque.size(); i++){
      try{
          if (myDeque.at(i) &gt; 10){
              //do stufff
          }
      }
      catch (...){
          cout &lt;&lt; "ERROR" &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>I assume, that this happens due to this multi-thread access of the deque.
  I cannot catch the error with  a <code>try-catch</code> block. Can't I do this, because it's thrown in a deeper "plane"?
  Is there a possibility to fix this error?</p>