title: Accessing a thread's private memory in OpenMP
body: <p>According to the <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.107.9768">OpenMP Memory Model</a>, the following is incorrect:</p>
  
  <pre><code>int *p0 = NULL, *p1 = NULL;
  #pragma omp parallel shared(p0,p1)
  {
    int x;
    // THREAD 0              // THREAD 1
    p0 = &amp;x;                 p1 = &amp;x;
    *p1 ...                  *p0 ...
  }
  </code></pre>
  
  <p>My example looks like the following though:</p>
  
  <pre><code>int *p0 = NULL, *p1 = NULL;
  #pragma omp parallel shared(p0,p1)
  {
    int x;
    // THREAD 0              // THREAD 1
    p0 = &amp;x;                 p1 = &amp;x;
    #pragma omp flush
  
    #pragma omp barrier
    *p1 ...                  *p0 ...
    #pragma omp barrier
  }
  </code></pre>
  
  <p>Would this be incorrect? I cannot find something in the memory model that would disallow this.</p>
  
  <p>I assume that my toy example is correct, as in the memory model in 3.1 they allow a task to have access to a private variable as long as the programmer ensures that it is still alive. Given the fact that tasks can be untied, they can in theory execute within a different worker thread, therefore allowing an OpenMP thread access to the private memory of another.</p>