当您想要测试interruption_rerequested()时,为什么要使用boost disable_interr
Why use boost disable_interruption when you want to test for interruption_requested()?
我在很多地方看到这样的代码:
void threadFunction()
{
boost::this_thread::disable_interruption disable;
while (!boost::this_thread::interruption_requested())
{
//do stuff
}
}
对我来说,这看起来像是我"禁用"了线程函数,使其不被中断,但随后我再次测试中断。神奇的是,它起作用了。有人能向我解释一下它在幕后的实际作用吗?非常感谢。
disable_interruption
防止线程实际被中断;它不会阻止设置中断状态。然后interruption_requested
测试中断状态是否已设置。
参见Boost文档:具体地;中断";区段
各种方法被归类为"中断点",如果在请求中断时调用它们,则会引发异常,除非中断已被禁用。
简而言之:
- 禁用中断可防止中断实际停止线程,但中断仍将线程标记为"请求中断"
interruption_requested
方法检查是否已请求中断
相关文章:
- 为什么 boost::interprocess::managed_shared_memory 在施工时会抛出 boost
- 为什么 boost::comb 对结构化绑定的支持缺少结构化绑定机制对 boost::tuples::cons 的适应?
- 为什么 Boost multi_index只修改第一个索引的键时对第二个索引进行比较?
- 为什么 boost::asio::ip::tcp::basic_stream_socket::available 的运行
- 为什么 Boost:正则表达式没有按预期找到所有结果?
- 为什么 boost::locale::to_title 不返回预期的输出?
- 为什么Boost Variant使用模板构造函数而不是Boost::beast::websocket::stream的移
- C++,自使用boost和std::chrono的纪元以来的时间?为什么 Boost 版本慢 10 倍?
- 为什么 Boost unordered_map 在第一次插入时需要太多时间?
- 为什么 boost::replace_all_copy 不起作用?C++
- cpp 为什么 boost::线程内部的循环不遍历所有值并且推送相同的值?
- 这是 boost::filesystem 中的错误吗?为什么 boost::filesystem::p ath::str
- 为什么 boost 文件系统和 libpq-fe 标头不会在同一个文件中编译
- 为什么 boost asio 中的 async_read 将 const MutableBufferSequence 作
- 为什么 boost interprocess_condition notify_one陷入僵局?
- 当用绝对时间调用时,为什么BOOST :: TIMED_WAIT块永远
- 为什么BOOST :: HANA :: EXAREMIS ::键入实验功能?类型列表的棘手是什么
- 为什么Boost Serialization使用的类版本限制为8位
- 为什么 boost::optional::is_initialized() 被弃用了?
- 为什么"boost::lower_bound"按值获取其参数?