可能重复:
C++11 thread_local in gcc - alternatives
Is there any way to fully emulate thread_local using GCC's __thread?如何在C++中初始化线程局部变量?
我想用C++ 11 thread_local
创建和使用thread_local变量,但它尚未由海湾合作委员会的支持,我我正在使用gcc特定的__thread
。我声明的变量的方法是
myClass
{
public:
static __thread int64_t m_minInt;
};
__thread int64_t myClass::m_minInt = 100;
当我编译它,我得到这样
error: ‘myClass::minInt’ is thread-local and so cannot be dynamically initialized
错误如何正确地做到这一点?
PS:gcc版本:4.6.3
@betabandido您链接的问题讨论了在C++ 11中thread_local的替代方案。我的问题是如何使用gcc的__thread。特别是有问题的错误消息。我试图在其他地方找到它,但无法得到它。谢谢。 – polapts