Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你能像取消 pthread 一样取消 Boost Thread 吗?
我正在编写一个简单的看门狗来在工作线程崩溃时终止它们,并且似乎没有办法简单地取消 Boost Thread 库中的线程。
他们不支持取消,这是一件好事,因为它会导致各种微妙的问题。
查看涵盖线程中断和 boost::thread_interrupted 异常的文档部分,并设计一些可以让您完成您想要的事情同时还可以清理的东西。
他们不支持开箱即用的取消(正如Duck所指出的那样),但是根据您的工作线程内部正在进行的处理,我会考虑使用 aboost::condition来通知线程它应该完成(干净地)尽早。
boost::condition