这个声明:
___thread A a;
生成此错误:
cannot be thread-local because it has non-POD type
A在哪里
class A{
public:
// function declaration
private:
// data members
};
我正在尝试使用命令 ogs includes & ogs mk 在 Linux 上进行编译。 我们有静态线程,即在我们的应用程序进入之前,我们知道线程的数量,因此目前的工作是通过声明 A 的数组来完成的,即
A a[Number of threads].
我该如何解决这个问题?
最佳答案
假设您使用 gcc,线程本地存储仅支持 POD 类型,即纯数据结构。
您可以尝试将数据提取到一个单独的 struct 中并使其成为本地线程(实际上,这在任何情况下都是一个好主意,因为使方法成为本地线程没有多大意义)。
关于C++ 编译器错误 "cannot be thread-local because it has non-POD type”“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13631989/