本文介绍了提升线程取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以像一个pthread一样取消Boost线程吗?

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

我写一个简单的看门狗来终止工作线程,如果它们崩溃了,是一种简单地取消Boost Thread库中的线程的方法。

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.

推荐答案

它们不支持cancel,好的东西,因为它可以导致各种各样的细微问题。

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

看看文档的部分,涵盖线程中断和boost :: thread_interrupted异常和时尚的东西允许你完成你想要的,同时也清理的东西。

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.

这篇关于提升线程取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:26