Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you know of some performances test of the different ways to get thread local storage in C++?

Tags:

People also ask

What is thread local storage in C?

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 runtime model GCC uses to implement this originates in the IA-64 processor-specific ABI, but has since been migrated to other processors as well.

How does thread local storage work?

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.

Why do we need thread local storage?

We need thread-local storage to create libraries that have thread-safe functions, because of the thread-local storage each call to a function has its copy of the same global data, so it's safe I like to point out that the implementation is the same for copy on write technique.

Is thread local storage slow?

TLS is always going to be slow relative to simple access. Accessing TLS globals in a tight loop is going to be slow, too. Try caching the TLS value in a temporary instead.


I'm doing a library that makes extensive use of a thread local variable. Can you point to some benchmarks that test the performances of the different ways to get thread local variables in C++:

  • C++0x thread_local variables
  • compiler extension (Gcc __thread, ...)
  • boost::threads_specific_ptr
  • pthread
  • Windows
  • ...

Does C++0x thread_local performs much better on the compilers providing it?