The C++11 standard contains a new addition - the thread_local specifier - which makes static variables thread-local. The standard thread_local supports non-trivial types - those with constructors and destructors. GCC unfortunately supports only trivial types via __thread
specifier provided as extension. Is there's a way to emulate thread_local
on top of __thread
? The implementation of __thread
is very fast (equivalent to regular variable plus two indirections), so I want to avoid library functions in the hot path.
I'm using GCC and Linux. Portability is not required.