C++ c++;函数内线程函数
我正在以以下方式创建一个boost线程C++ c++;函数内线程函数,c++,boost,boost-thread,C++,Boost,Boost Thread,我正在以以下方式创建一个boost线程 static void* ThreadFuncCall(void *arg) { return ((TestClass*)arg)->Thread1Func((TestClass*)arg Thread1 = new boost::thread((boost::bind(&TestClass::ThreadFuncCall, this))); void* TestClass::Thread1Func(TestClass* testClass
static void* ThreadFuncCall(void *arg) { return ((TestClass*)arg)->Thread1Func((TestClass*)arg
Thread1 = new boost::thread((boost::bind(&TestClass::ThreadFuncCall, this)));
void* TestClass::Thread1Func(TestClass* testClass){
//Accessing the member variables here
testClass->m_active = true;
//call another function here
}
在Thread1Func
中,我想调用另一个函数,我想将TestClass
的对象传递给它,就像我传递给ThreadFuncCall
一样
我想知道我们是否可以在线程函数中调用另一个函数
如果可以,那么如何将
TestClass
的对象传递给它?是的,您可以从另一个函数调用函数。函数调用将在与原始函数相同的线程中执行。要将指向该类的指针传递给另一个函数,请执行与ThreadFunc1相同的操作
void* TestClass::Thread1Func(TestClass* testClass){
//Accessing the member variables here
testClass->m_active = true;
//call another function here
int i = function1(testClass, "hello world");
}
int function1(TestClass* testClass, char* text){
testClass->printText(text);
return 7;
}
这个“另一个函数”是在哪里定义的?在线程函数中,你不能调用“testClass->functionname()”吗?