Boost Thread Cancelling

一曲冷凌霜 提交于 2019-12-09 12:14:28

问题


Can you cancel a Boost Thread as you would a pthread?

I'm writing a simple watchdog to terminate worker threads if they crash and there doesn't seem to be a way to simply cancel a thread in the Boost Thread library.


回答1:


They don't support cancel, which is a good thing since it can cause all manner of subtle problems.

Take a look at the section of docs that cover thread interruption and the boost::thread_interrupted exception and fashion something that allows you to accomplish what you want while also cleaning things up.




回答2:


They don't support cancelling out of the box (as pointed out by Duck), however depending on the processing going on inside your worker thread(s), I'd consider using a boost::condition to notify the thread that it should finish (cleanly) at the earliest opportunity.



来源:https://stackoverflow.com/questions/1039918/boost-thread-cancelling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!