【发布时间】:2010-06-28 07:59:36
【问题描述】:
我有一些看起来像这样的代码:
线程 0:
CMyOtherClass *m_myclass;
CMyClass::SomeFunc(DWORD SomeParam)
{
m_myclass = new CMyOtherClass(SomeParam);
}
线程 1:
CMyClass::InsideSecondThread()
{
MySecondThreadFunc(*m_myclass);
}
CMyClass::MySecondThreadFunc(MyOtherClass& myclass)
{
// do something with myclass variable....
// What about thread safety??? Is this not now a shared variable?
// or have we passed a copy and are we safe?
// SomeParam should be the same while in this thread, however it can be changed by Thread 0
}
所以我的问题是,如果你要跨线程传递这个 m_myclass 变量,这是否是线程安全的?
【问题讨论】:
标签: c++ pointers multithreading thread-safety