title: How to avoid `deque iterator not dereferencable` in a std::deque ? Locks?
body: <p>Currently in my project I have two static methods <code>PushObjects</code> and <code>ProcessObject</code>. The <code>PushObject</code> method pushes back data to a static deque and this method can be accessed by multiple threads but the <code>ProcessObject</code> is always used by a single thread and is used to retrieve objects from the top and remove them.Now my problem is no matter what I try I always eventually (sooner or later get a <code>deque iterator not dereferencable</code> error.Any suggestions on what I could do to stop this issue. An abstract of my <code>PushObjects</code> and <code>ProcessObject</code>are given below</p>
  
  <pre><code>    void foo::PushObjects(obj A)
      {
          try
          {
              {//Begin Lock
                  boost::lock_guard&lt;boost::mutex&gt; lock(mutex_push);
                  mydeque.push_back(A);
              }//End Lock
              condition_read.notify_one(); //Inform the reader that it could start reading 
          }
          catch (std::exception&amp; e)
          {
              __debugbreak();
          }
      }
  
  
      This is the static Reader method
  
      void foo::ProcessObject()
      {
          {//Begin Lock
              boost::unique_lock&lt;boost::mutex&gt; lock(mutex_process);
              while(true)
              {
                      while(mydeque.empty()) { condition_read.wait(lock); }
                      try
                      {
                          if(!mydeque.empty())
                          {
                                  obj a = mydeque.front();
                                  ......Process the object........
                                  mydeque.pop_front();
                          }
  
                      }
                      catch (std::exception&amp; e)
                      {
                          __debugbreak();
                      }
              }//end while
          }//End lock
      }
  </code></pre>
  
  <p>From what I have read is that iterators become invalid once items are added or removed from the deque. Is there a way to resolve this issue. </p>