c++ - 是否预计 boost::thread_specific_ptr<>::get() 的使用会很慢?有什么解决办法吗?

标签 c++ multithreading boost boost-thread

我目前正在使用 Valgrind 的“Callgrind”分析一个存在性能问题的应用程序。在查看分析数据时,似乎有 25% 的处理时间花在 boost::detail::get_tss_data 的应用程序中,其主要目的是物理模拟和可视化。

get_tss_data 显然是由 thread_specific_ptr::get

调用的

有人认为这是预期的吗?它通常是否暗示其他特定的东西?

编辑:

我的平台是:Linux-2.6.32、x86、GCC 4.4.3、libc6-2.11.1/libpthread-2.11.1

最佳答案

thread_specific_ptrpthread_setspecific/pthread_getspecific 用于 POSIX 系统,这不是最快的。

如果您使用的是 POSIX 系统,则可以使用 __thread 存储说明符。但是,它只能与常量表达式的初始化程序一起使用,例如 gcc's __thread

对于 Windows,类似的说明符是 _declspec(thread)

关于c++ - 是否预计 boost::thread_specific_ptr<>::get() 的使用会很慢?有什么解决办法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5398987/

相关文章:

multithreading - 延迟处理更多请求/秒

c++ - 为 Boost 日志对象重载 << 运算符

c++ - 什么时候结束?

c++ - 编写一个使用 int 或 enum 参数的函数

Java线程设计

c++ - 在 PThreads 或 Windows 中线程退出时调用函数

c++ - Boost.Regex 支持 icu/unicode

c++ - std::vector<bool> 只有一个真元素

c++ - 是否可以将参数包扩展为不同的成员函数?

c++ - 模板参数 '(type)0' 与 'EnumValue' 不匹配