title: Is assignment to a std::vector element thread-safe?
body: <p>I have made a thread pool which writes to the same vector at the same time.  </p>
  
  <p>Is this implementation thread safe?</p>
  
  <p>If it is not, how should I fix it?</p>
  
  <pre><code>std::vector&lt;double&gt; global_var;
  
  void func1(int i)
  {
      global_var[i]=some_computation(i /* only depends on i */);
  }
  
  void load_distribution()
  {
      const int N_max=100;
      global_var.assign(N_max,0.0);
      std::vector&lt;std::thread&gt; th_pool;
      for(long i=0;i&lt;N_max;i++)
          th_pool.push_back(std::thread(func1,i));
  
      for(std::thread&amp; tp : th_pool)
          tp.join();
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p><code>global_var</code> will not be touched by any other part of the program before all threads terminated.</p>