__thread about the same as the threadprivate OpenMP directive. To a large extent (read when no C ++ objects are involved), both are often implemented using the same main compiler mechanism and are therefore compatible, but this is not guaranteed to always work. Of course, the real world is far from ideal, and we sometimes have to sacrifice portability for the fact that you have things that work within certain developmental constraints.
threadprivate is a directive, not a suggestion, so you need to do something like:
#include "header_providing_a.h" #pragma omp threadprivate(a) void parallel_using_a() { #pragma omp parallel default(none) ... ... use 'a' here }
GCC (at least version 4.7.1) treats __thread as an implicit threadprivate declaration, and you don't need to do anything.
source share