Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the current state of support for 'thread_local' across platforms?

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.

  • Windows (gcc, clang, msvc)
  • Linux (gcc, clang)
  • OS X (gcc, clang)
  • Android (gcc, clang)
  • iOS
  • BlackBerry
  • Windows Phone/RT/etc
like image 944
Prismatic Avatar asked Apr 01 '15 19:04

Prismatic


People also ask

Is thread local storage fast?

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.

Why do we need thread local storage?

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.

What is TLS memory?

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.

What is thread local storage in Linux?

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.


1 Answers

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.

like image 85
Christophe Avatar answered Oct 12 '22 09:10

Christophe