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.
Accessing thread local variables is cheap in both cases ; the lookup done by the glibc is very fast (and takes a constant time). But if your code is — or could be — loaded as a dynamic module and is speed-critical, then it can be worth spending some time to avoid this lookup.
With thread local storage (TLS), you can provide unique data for each thread that the process can access using a global index. One thread allocates the index, which can be used by the other threads to retrieve the unique data associated with the index.
Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread. This is sometimes needed because all threads in a process share the same address space.
Thread-local storage (TLS) is a mechanism by which variables are allocated such that there is one instance of the variable per extant thread. The run-time model GCC uses to implement this originates in the IA-64 processor-specific ABI, but has since been migrated to other processors as well.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With