(mutex) lock for callback function C++
<p>In a multi-threaded application, <code>mutex::lock</code> is used to prevent two threads accessing the same memory location at the same time. In my application, I do not use multiple threads but I have a <strong>callback function</strong> that writes to a vector and a loop in the main function, that reads it. Sometimes, I get this error:</p>

<blockquote>
  <p>Vector iterator + offset out of range</p>
</blockquote>

<p>After checking the vector in debugging, all seems to be fine: the number of elements is right and none of the elements in invalid. Is there a similar possibility for callback functions?</p>