升压,C ++如何杀死线程被另一个线程打开? [英] Boost, C++ how to kill thread opened by another thread?

查看:208
本文介绍了升压,C ++如何杀死线程被另一个线程打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一些主要的功能。 24时第二个它会打开一个提升线程 A 与功能。该函数取与数据的缓冲器。它启动提振定时器。它打开另一个线程 B 与缓冲区发送到它的功能。我需要线程A如果它在执行很长的路要走2杀死线程B。当然,如果线程B在时间上已经执行我不需要杀死它应该杀了自己。什么提升功能可以帮我杀了创建的线程?(不参加 - 停止/终止或类似的东西)

so I have some main function. 24 time a second it opens a boost thread A with a function. that function takes in a buffer with data. It starts up a boost timer. It opens another thread B with a function sending buffer into it. I need thread A to kill thread B if it is executing way 2 long. Of course if thread B has executed in time I do not need to kill it it should kill itself. What boost function can help me to kill created thread (not join - stop/kill or something like that)?

BTW我可以在不影响功能的速度,我在exequting线程B这就是为什么我需要能够在需要的时候杀死它。

BTW I cannot affect speed of Function I am exequting in thread B thats why I need to be capable of killing it when needed.

推荐答案

您正在查找的术语是取消,为的 pthread_cancel可以(3)。取消麻烦,因为被取消的线程可能不会执行C ++析构函数或释放的出路锁......但话又说回来它可能;不确定性实际上是更糟的不是一个明确的没有。

The term you are looking for is "cancellation", as in pthread_cancel(3). Cancellation is troublesome, because the cancelled thread might not execute C++ destructors or release locks on the way out ... but then again it might; the uncertainty is actually worse than a definitive no.

由于这个原因,提高线程不支持消除(参见例如此旧的问题),但它们支持<一个href=\"http://www.boost.org/doc/libs/1_38_0/doc/html/thread/thread_management.html#thread.thread_management.interruption\"相对=nofollow>中断,你也许能够弯曲,以适应。中断的工作原理是一个常规的C ++异常所以它具有predictable语义的方式。

Because of this, boost threads do not support cancellation (see for instance this older question) but they do support interruption, which you might be able to bend to fit. Interruption works by way of a regular C++ exception so it has predictable semantics.

这篇关于升压,C ++如何杀死线程被另一个线程打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆