对于pthread的,如何从主线程杀子线程 [英] For pthread, How to kill child thread from the main thread

查看:122
本文介绍了对于pthread的,如何从主线程杀子线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用pthread_create的创建多个子线程。而此时,主线程要杀死所有的子线程还是会有段falut。它的功能,我应该用它来完成呢?我搜索从谷歌的答案,得到了像pthread_kill功能。但我不知道哪一个信号,我应该发送给子线程要杀死他们。我的运行环境是RHEL 5.4和编程语言是C。

I use pthread_create to create several child threads. At a time, the main thread wants to kill all child threads or there will be segment falut. Which function should I use to finish that? I searched the answer from google and got function like pthread_kill. But I did not know which signal should I send to the child thread to kill them. My running environment is RHEL 5.4 and programming language is C.

推荐答案

有可能用于取消线程 pthread_cancel可以 。然而,这通常不是最好的做法,虽然在极端情况下像一个段错误就可能conisd​​ered一个合理的方法。

It is possible to "cancel" a thread using pthread_cancel. However, this isn't typically best practice though under extreme circumstances like a SEGFAULT it may be conisdered a reasonable approach.

这篇关于对于pthread的,如何从主线程杀子线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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