我正在使用一个封装 thread_group 的类,并且对此有一些疑问
class MyGroup{
private:
boost::this_thread::id _id;
boost::thread::thread_group group;
int abc;
//other attributes
public:
void foo();
};
在类构造函数中,我启动 N 个线程
for (size_t i=0;i<N;i++){
group.add(new boost::thread(boost::bind(&foo,this)));
}
void foo(){
_id = boost::this_thread::get_id();
//more code.
abc++ //needs to be sync?
}
所以,这是我的问题。
类属性需要同步吗?
每个线程都有不同的ID吗?例如,如果我有
void bar(){
this->id_;
}
这会导致每个线程的 id 不同,还是每个人都一样?
提前致谢 !