Reputation: 3348
I'd like a summary of what the current state of support for the 'thread_local' keyword is across different compilers and platforms.
I'm specifically interested in common desktop and mobile platforms. The information I could find seems spotty at best with reports of it working on some platforms and not on others or mentions of support being a WIP. Answers that confirm support (or lack of support) even for single platforms are welcome. Please mention any caveats to the support if there are any.
Upvotes: 13
Views: 3100
Reputation: 32884
GCC supports thread-local storage (thread_local
storage duration specifier) since GCC 4.8 i.e. since 2013 March on Linux, macOS and other Unix-likes.
On Windows, MinGW (Thread model: POSIX) however has a bug: thread_local
destructors broken with posix threading since 2015 which makes it still not easy to create thread-local variables on Windows. This includes GCC's extension of using __thread
storage specifier on MinGW.
Upvotes: 1
Reputation: 73366
In complement to the other excellent answer: MSVC 2013 doesn't currently support it.
This page on support of core language features claims it's partially supported. However, looking at the details it appears that:
Thread-local storage is listed as "Partial" because VC has provided the non-Standard extension __declspec(thread) for many years. (Notably, C++11 thread_local supports non-PODs, but __declspec(thread) doesn't.)
It's implemented in MSVC 2014 CTP 3 (since summer 2014; See blog entry) and is available in MSVS2015.
Upvotes: 8
Reputation: 224834
For clang
, you can check the C++11 implementation status:
Language Feature: Thread-local storage
C++11 Proposal: N2659
Available in Clang? Clang 3.3
and
Clang 3.3 and later implement all of the ISO C++ 2011 standard. ...
thread_local
support currently requires the C++ runtime library from g++-4.8 or later.
You could also use libc++, which is "a 100% complete C++11 implementation on Apple's OS X."
Upvotes: 3