Home > Software design >  openmp threadprivate and gcc __thread compatibility
openmp threadprivate and gcc __thread compatibility

Time:10-08

My understanding of "openMP threads" is that they may not map to OS thread one to one. The openMP spec doesn't appear to require this.

GCC has the __thread keyword, which is for thread local storage (thread as in OS thread based on my interpretation). Does this mean GCC __thread is not compatible with openMP's threadprivate? If the openMP spec allows multiplexing openMP threads onto OS thread, then I think __thread and threadprivate are not compatible.

I saw there was this question asked a while ago for an older version of GCC, and it says that they are basically compatible. Is it still true for newer versions of GCC (say GCC 11.2)?

CodePudding user response:

It is true for most implementations. All OpenMP implementations that I know of are based on OS-level threads (pthreads on Linux, Winthreads on Windows) and thus should not have a problem with the __thread keyword of C or thread_local in C .

But as you rightfully say, this is a matter of how things have been implemented. The OpenMP API does not make any statements about how things have to work internally, so technically an implementation that is not based on OS-level threads could be done and then there might be some breakage with base-language features, for which the OpenMP API does not specify thre interaction.

  • Related