From the GCC 4.8 draft changelog:
G++ now implements the C++11
thread_local
keyword; this differs from the GNU__thread
ke
C++11 thread_local has the same runtime effect as the __thread specifier (__thread
is not part of the C standard; thread_local
is part of the C++ standard)
it depends where the TLS variable (declared with __thread
specifier) is declared.
-fPIC
compiler option) and -ftls-model=initial-exec
compiler option is specified then access is fast; however the following limitation applies: the shared library can't be loaded via dlopen/dlsym (dynamic loading), the only way of using the library is to link with it during compilation (linker option -l
) -fPIC
compiler option set) then access is very slow, as the general dynamic TLS model is assumed - here each access to a TLS variable results in a call to _tls_get_addr()
; this is the default case because you are not limited in the way that the shared library is used. Sources: ELF Handling For Thread-Local Storage by Ulrich Drepper https://www.akkadia.org/drepper/tls.pdf this text also lists the code that is generated for the supported target platforms.