我想使用 boost::thread interrupt() 来中断一个线程。我有以下代码不会引发 boost::thread_interrupted& 异常:
int myClass::myFunction (arg1, arg2) try{
//some code here
do {
boost::this_thread::interruption_point();
//some other code here
} while (counter != 20000);
}catch (boost::thread_interrupted&) {
cout << "interrupted" << endl;
}
如果我将 boost::this_thread::interruption_point() 替换为 boost::this_thread::sleep( boost::posix_time::milliseconds(150)) 异常会抛出并且中断正常工作。
有人可以解释为什么 boost::this_thread::interruption_point() 不会抛出预期的异常吗?