title: std::vector natural thread safe while iteration
body: <p>Assuming, I have std::vector and two threads.</p>
  
  <p>First thread is processing <strong>erase</strong> function while second thread is in <strong>for-loop</strong></p>
  
  <p>Is this situation a thread-safe?</p>
  
  <p>Would second thread keep running or throwing an exception?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;thread&gt;
  
  int main()
  {
      std::vector&lt;int&gt; intContainer;
  
      for ( int index = 0; index &lt;= 100000; ++index){
          intContainer.push_back(index);
      }
  
      std::thread t1([&amp;](){
          while ( 1 ){
              intContainer.erase( std::find(intContainer.begin(), intContainer.end(), random(1, 100000) ) );
              std::this_thread::sleep_for(std::chrono::milliseconds(500));
          }
      });
  
      std::thread t2([&amp;] (){
          for ( auto&amp; val : intContainer ){
              std::cout &lt;&lt; val &lt;&lt; std::endl;
          }   
      });
  
      t1.join();
      t2.join();
  
      return 0;
  }
  </code></pre>