title: How to sync "for" loop counter in multithread?
body: <p>How to sync "for" loop counter on multithread?</p>
  
  <p>If these multi thread program</p>
  
  <pre><code>void Func(int n){
   for(int i=0; i&lt;n; i++){ //at the same time with other Func()
    cout &lt;&lt; i &lt;&lt;endl;
   }
  }
  
  void main(){
   std::thread t1(Func(2));
   std::thread t2(Func(2));
   t1.join();
   t2.join();
  }
  </code></pre>
  
  <p>When executing Func() in parallel , I want to sync "for" loop counter "i".</p>
  
  <p>For example, the program has possibility to output the result</p>
  
  <pre><code>0
  1
  0
  1
  </code></pre>
  
  <p>but I want to always get the result</p>
  
  <pre><code>0
  0
  1
  1
  </code></pre>
  
  <p>Can I it?</p>