【发布时间】:2014-10-03 07:21:51
【问题描述】:
boost::thread interrupt() 仅在第一次执行中断点时抛出异常?我的情况如下。
我创建了一个boost::thread,它执行functionA.functionA调用functionB,当在functionB上时,我们调用函数threadInterrupt.functionB抛出一个boost::thread_interrupted异常并返回functionA.我的问题是在执行另一个中断点时是否会在函数A中抛出一个新的boost::thread_interrupted异常。
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;
}
}
【问题讨论】:
标签: c++ boost boost-thread interruptions