Is it expected that use of boost::thread_specific_ptr<>::get() be slow? Any work arounds?

前端 未结 2 1543
清歌不尽
清歌不尽 2021-02-07 15:02

I\'m currently profiling an application with performance problems using Valgrind\'s \"Callgrind\". In looking at the profiling data, it appears that a good 25% of processing tim

2条回答
  •  春和景丽
    2021-02-07 15:37

    thread_specific_ptr uses pthread_setspecific/pthread_getspecific for POSIX systems which is not the fastest possible.

    If you are on a POSIX system, you can use the __thread storage specifier. However, it can only be used with initializers that are constant expressions e.g gcc's __thread

    For Windows, a similar specifier is _declspec(thread).

提交回复
热议问题