简体   繁体   English

是否可以使用boost :: thread杀死线程?

[英]Is it possible to kill a thread using boost::thread?

For a program I'm working on, I am trying to add a cancel function which should instantly kill all working threads. 对于我正在开发的程序,我试图添加一个cancel函数,该函数应立即杀死所有工作线程。

I wonder how this could be realized. 我不知道如何实现。 I am aware that this might result in a corrupted state. 我知道这可能会导致损坏状态。

(I also have access to all of the working threads. I just couldn't find a way to forcefully kill them.) (我也可以访问所有工作线程。我只是找不到一种方法来强制杀死它们。)

If it's not possible with the boost::thread libary I do not want to know it! 如果boost :: thread libary无法实现,我不想知道!

The Best way may be interruption point . 最好的方法可能是中断点 Define it. 定义它。 And you code will stop as far as it achieve the nearest interruption point. 并且您的代码将停止直到达到最近的中断点。

According to the answer here: Kill a blocked Boost::Thread 根据这里的答案: 杀死阻塞的Boost :: Thread

Platform specific code using the native_handle may be your only option. 使用native_handle的特定于平台的代码可能是您唯一的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM