杀死pthread库线程 [英] Kill Thread in Pthread Library

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

问题描述

我用在pthread_create(安培;线程1,和放大器; ATTRS,// ...,//...);键,如果需要一些条件发生需要杀死这个线程怎么杀的?

I use pthread_create(&thread1, &attrs, //... , //...); and need if some condition occured need to kill this thread how to kill this ?

推荐答案

第一家店线程ID

pthread_create(&thr, ...)

然后再打

pthread_cancel(thr)

然而,这不是建议的编程习惯!这是更好地使用像信号量或消息的线程间通信机制的线程沟通,它应该停止执行。

However, this not a recommended programming practice! It's better to use an inter-thread communication mechanism like semaphores or messages to communicate to the thread that it should stop execution.

请注意该pthread_kill(...)实际上不终止接收线程,而是提供了一个信号给它,这取决于信号和信号处理程序会发生什么。

Note that pthread_kill(...) does not actually terminate the receiving thread, but instead delivers a signal to it, and it depends on the signal and signal handlers what happens.

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

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