我想使用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()没有引发预期的异常吗?