views:

168

answers:

2

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?

+1  A: 

You can always use time.h. Its your friend when testing performance stuff and nothing else is available.

thyrgle
What I'm looking for is a benchmark of the use in different contexts. Of course I can do it myself, but I would prefer to reuse one if it exists.Maybe you are interested in Boost.Chrono :)
Vicente Botet Escriba
+1  A: 

These are typically implemented as a simple offset in an array in the thread's private memory space. So, accessing the thread specific variable X, of type T,

T y = X;

roughly translates to,

T y = *(T*)(cur_thread.local_tbl[key_X]);

which is too simple to expect a wide variation in performance between implementations. That said, if you find any such benchmarks, please follow up here.

John
The current Boost implementation is not so simple, as the key is the address of the thread_specific_pointer variable.Compilers can now the keys at compile time, and can make some optimizations.So I expect a wide variation between available implementations, that can be determinant to libraries that make a deep use of thread specific storage.
Vicente Botet Escriba