title: Accessing the executing thread's private variables within a task in OpenMP
body: <p>I am trying to learn OpenMP, and have stumbled upon the fact that threads do not retain their own data when executing tasks, but they rather have a copy of the data of the thread which has generated the task.  Let me demonstrate it with an example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;omp.h&gt;
  
  int main()
  {
  #pragma omp parallel num_threads(4)
      {
          int thread_id = omp_get_thread_num();
  #pragma omp single
          {
              printf("Thread ID of the #single: %d\n", omp_get_thread_num());
              for (int i = 0; i &lt; 10; i++) {
  #pragma omp task
                  {
                      sleep(1);
                      printf("thread_id, ID of the executing thread: %d, %d\n", thread_id, omp_get_thread_num());
                  }
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>An example output of this code is as follows:</p>
  
  <pre><code>Thread ID of the #single: 1
  thread_id, ID of the executing thread: 1, 2
  thread_id, ID of the executing thread: 1, 0
  thread_id, ID of the executing thread: 1, 3
  thread_id, ID of the executing thread: 1, 1
  ...
  </code></pre>
  
  <p>It is evident that the <code>thread_id</code> within the task refers to a copy that is assigned to the <code>thread_id</code> of the thread that has created the task (i.e. the one running the <em>single</em> portion of the code).</p>
  
  <p>What if I wanted to refer the executing thread's own private variables then? Are they unrecoverably shadowed? Is there a clause to make this code output <code>number, same number</code> instead at the end of each line?</p>