Почему потоки c ++ 11 становятся неприсоединяемыми при использовании вложенных прагм OpenMP?
Следующий код должен быть довольно простым, но, похоже, в конечном итоге он зависает при попытке выполнить .join () для потоков с вложенным кодом OpenMP. Использование компилятора GCC 4.7.2 x64 с pthreads изhttp://sourceforge.net/projects/mingwbuilds с участиемg++ threadexample.cpp -Wall -std=c++11 -fopenmp -o threads
// threadexample.cpp
#include <iostream>
#include <thread>
#include <omp.h>
using namespace std;
void hello(int a) {
#pragma omp parallel for
for (int i=0;i<5;++i) {
#pragma omp critical
cout << "Hello from " << a << "! " << "OMP thread iter " << i << endl;
}
cout << "About to return from hello function" << endl;
}
int main (int argc, char ** argv) {
thread t1(hello, 1); //fork
cout << "t1 away!" << endl;
thread t2(hello, 2);
cout << "t2 away!" << endl;
t1.join(); //join
cout << "thread 1 joined" << endl;
t2.join();
cout << "thread 2 joined" << endl;
return 0;
}