我正在嘗試使用C++ 11的std::thread
類來運行並行執行的類的成員函數。如何在使用C++ 11線程類的單獨線程中執行類成員函數?
頭文件的代碼類似於:
class SomeClass {
vector<int> classVector;
void threadFunction(bool arg1, bool arg2);
public:
void otherFunction();
};
cpp文件是類似於:在Mac OS X 10.8.3
void SomeClass::threadFunction(bool arg1, bool arg2) {
//thread task
}
void SomeClass::otherFunction() {
thread t1(&SomeClass::threadFunction, arg1, arg2, *this);
t1.join();
}
我使用的Xcode 4.6.1。我使用的編譯器是Xcode附帶的Apple LLVM 4.2。
上述代碼無效。編譯器錯誤說"Attempted to use deleted function"
。
在線程創建線上,它顯示以下按摩。
In instantiation of function template specialization 'std::__1::thread::thread<void (SomeClass::*)(bool, bool), bool &, bool &, FETD2DSolver &, void>' requested here
我是新的C++ 11和線程類。有人能幫助我嗎?
這是值得指出的是,有機磷農藥的代碼是無用的,如果他稱之爲'。加入()'立刻。 –
非常感謝它的工作。 –