title: How to write to file from different threads, OpenMP, C++
body: <p>I use openMP for parallel my C++ program. My parallel code have very simple form</p>
  
  <pre><code>#pragma omp parallel for shared(a, b, c) private(i, result)
          for (i = 0; i &lt; N; i++){
           result= F(a,b,c,i)//do some calculation
           cout&lt;&lt;i&lt;&lt;" "&lt;&lt;result&lt;&lt;endl;
           }
  </code></pre>
  
  <p>If two threads try to write into file simultaneously, the data is mixed up.
  How I can solve this problem?</p>