title: OpenMP assign the execution of a function to a thread?
body: <p>Basically I need the Master thread to keep doing some operation based on the value of some global variables that can be edited (at some selected intervals) by a secondary thread. Something Like:</p>
  
  <pre><code>vector&lt;int&gt; mySharedVar;
  
  void secondaryThreadFunction() {
     Do some operations
     And update mySharedVar if necessarily  
  }
  
  int main() {
   int count = 0;
   while(true) {
      count++;
  
      if (count%100) {  //&gt; Each 100 iterations run a parallel thraed
        //&gt; RUN secondaryThreadFunction in a separateThread
      }
  
      this is the main thread that based its operation on mySharedVar
   }
  }
  </code></pre>
  
  <p>Which is the openmp command to run a single parallel thread with <code>secondaryThreadFunction();</code> ?</p>
  
  <p>Are there any other better way than this:</p>
  
  <pre><code>#pragma omp parallel num_threads(2)
      {
          int i = omp_get_thread_num();
  
          if (i == 0){
              mainThread();
          }
          if (i == 1 || omp_get_num_threads() != 2){
              secondaryThreadFunction();
          }
      }
  </code></pre>