title: C++ OpenMP parallel with a read-only reference variable
body: <p>I'm trying to run code in parallel with the GCC 4.4.7 version. I used the OpenMP library. I have a read-only variable (pointer to a class) which is shared by all the threads.</p>
  
  <p>The code is compiled and executed without any errors, but I do not obtain the same results when running the same code in a serial sequence (the results in the serial mode are true).
  The code looks like:</p>
  
  <pre><code>#include &lt;class1&gt;
  #include &lt;class2&gt;
  int main(){
      string a;
      int b1,b2,d;
      class1 c1(a,b1);
      c1.compute(d);
      int n_thread = 10; 
      int i,n=10;
      vector&lt;vector&lt;int&gt; &gt; res(n);
      omp_set_dynamic(0);            
      omp_set_num_threads(n_thread);   
  
      #pragma omp parallel for num_threads(n_thread) private(i)  shared(res) 
      for(i=0;i&lt;n;i++)
      {
          class1 c(c1.tab,b2);
          c.compute(d);
  
          class2 toto(b1,b2);
          toto.getvect(c1.tab,c.tab);//Inside toto, the c1.tab is read-only 
  
          #pragma omp critical
          {
              res[i] = vector&lt;int&gt; (toto.p);
          }
      }
  //the rest of the program when I use the c1 var and the res matrix.
  }
  </code></pre>
  
  <p>My first thought was that the problem is from the two reference variables <em>c</em> and <em>toto</em>, but these two variables are created at each thread, so they are private to each thread.
  I tried to use <em>c1</em> as <em>threadprivate</em> but there was a compilation error. If <em>c1</em> is declared as shared, there is no change at the output results. Maybe the problem is from the multiple acces to the smae variable at the same time ? How can I solve the problem ?</p>