This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/27557] OpenMP threadprivate directive does not work with non-POD types
- From: "yves.vandriessche at intel dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 18 Jun 2018 12:32:59 +0000
- Subject: [Bug c++/27557] OpenMP threadprivate directive does not work with non-POD types
- Auto-submitted: auto-generated
- References: <bug-27557-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27557
Yves Vandriessche <yves.vandriessche at intel dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yves.vandriessche at intel dot com
--- Comment #18 from Yves Vandriessche <yves.vandriessche at intel dot com> ---
As mentioned by Sameer, thread_local now works, but the threadprivate OpenMP
directive still fails with a "declared 'threadprivate' after first use" error.
My test fragment, is as follows. It should only print a single "ctor" and twice
the same set of distinct pointers:
#include <cstdio>
#include <omp.h>
struct Foo {
Foo() {puts("ctor");}
int a;
};
int bar() {
int sum=0;
// // alternative to omp threadprivate, works with gcc
// thread_local Foo local;
#pragma omp parallel reduction(+:sum)
{
static Foo local;
#pragma omp threadprivate(local)
local.a = omp_get_thread_num();
printf("%p\n", &local);
sum += local.a;
}
printf("%d\n", sum);
return sum;
}
int main(int argc, char** argv) {
bar();
bar();
return 0;
}