Do you know of some performances test of the different ways to get thread local storage in C++?
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 thre开发者_运维技巧ad_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?
You can always use time.h
. Its your friend when testing performance stuff and nothing else is available.
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.
精彩评论