Alex Rivera | Logout

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

Asked 2010-05-26T09:57:41.210
10

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?

Edit
Report

1 Answer

1

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.

answered 2010-06-12T16:19:12.323

Your Answer