【发布时间】:2012-08-18 00:11:28
【问题描述】:
可能重复:
C++11 thread_local in gcc - alternatives
Is there any way to fully emulate thread_local using GCC's __thread?
我想使用 c++11 thread_local 来创建和使用 thread_local 变量,但由于 gcc 尚不支持它,我正在使用 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 。特别是有问题的错误消息。我试图在别处找到它,但找不到它。谢谢。
标签: c++ multithreading gcc thread-local thread-local-storage