title: Why do c++11 threads become unjoinable when using nested OpenMP pragmas?
body: <p>The following code should be pretty straightforward but seems to end up in a hanging situation when trying to do a .join() on the threads with nested OpenMP code. Using GCC compiler 4.7.2 x64 with pthreads from <a href="http://sourceforge.net/projects/mingwbuilds" rel="nofollow">http://sourceforge.net/projects/mingwbuilds</a> with <code>g++ threadexample.cpp -Wall -std=c++11 -fopenmp -o threads</code></p>
  
  <pre><code>// threadexample.cpp
  #include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;omp.h&gt;
  
  using namespace std;
  
  void hello(int a) {
  
      #pragma omp parallel for
          for (int i=0;i&lt;5;++i) {
              #pragma omp critical
              cout &lt;&lt; "Hello from " &lt;&lt; a &lt;&lt; "! " &lt;&lt; "OMP thread iter " &lt;&lt; i &lt;&lt; endl;
          }
  
      cout &lt;&lt; "About to return from hello function" &lt;&lt; endl;
  }
  
  int main (int argc, char ** argv) {
  
      thread t1(hello, 1); //fork
      cout &lt;&lt; "t1 away!" &lt;&lt; endl;
      thread t2(hello, 2);
      cout &lt;&lt; "t2 away!" &lt;&lt; endl;
  
      t1.join(); //join
      cout &lt;&lt; "thread 1 joined" &lt;&lt; endl;
      t2.join();
      cout &lt;&lt; "thread 2 joined" &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>