boost::thread interrupt() 仅在第一次执行中断点时引发异常?我的情况如下。
我创建了一个boost::thread
执行functionA.
functionA
调用的函数functionB
,当functionB
我们调用函数时threadInterrupt.
functionB
会抛出boost::thread_interrupted
异常并返回functionA.
我的问题是boost::thread_interrupted
,当另一个中断点被执行时,是否会在函数 A 中抛出一个新的异常。
void MyClass::function(int arg1, int arg2) try {
boost::thread* t = new boost::thread(boost::bind(&MyClass::functionA, this, var1, var2));
} catch (...) {
cout << "function throw an exception" << endl;
}
void MyClass::functionA(int arg1, int arg2 ) try {
//some code here
try {
int retVal = MyClass::functionB(var);
boost::this_thread::interruption_point();
//some code here
} catch(boost::thread_interrupted&) {
cout << "thread interrupted in functionA" << endl;
}
} catch (...) {
cout << "functionA throw an exception" << endl;
}
int MyClass::functionB(int arg1) try {
//some code here
try {
boost::this_thread::interruption_point();
//some code here
} catch(boost::thread_interrupted&) {
cout << "thread interrupted in functionB" << endl;
return 0;
}
return 1;
} catch (...) {
cout << "functionB throw an exception" << endl;
return 1;
}
void MyClass::threadInterrupt() {
if (thr!=NULL) {
thr->interrupt();
thr->join();
delete thr;
thr=NULL;
}
}