我看到很多地方的代码都是这样的:
void threadFunction()
{
boost::this_thread::disable_interruption disable;
while (!boost::this_thread::interruption_requested())
{
//do stuff
}
}对我来说,这看起来像是“禁用”线程函数,使其不被中断,但我再次测试是否有中断。奇迹般地起作用了。有人能给我解释一下它在幕后到底做了什么吗?谢谢!
发布于 2015-03-17 12:56:45
disable_interruption防止线程实际被中断;它不阻止设置中断状态。然后interruption_requested测试是否设置了中断状态。
参见Boost文档:特别是“中断”部分
各种方法被归类为“中断点”,如果请求中断时调用它们,则会抛出异常,除非中断已被禁用。
因此,简而言之:
interruption_requested方法检查是否请求了中断。https://stackoverflow.com/questions/29099617
复制相似问题