pthread_kill
参考:
要点:
- 待取消线程需要注册信号处理函数,否则把主进程干掉了
-
外部线程发起kill
(触发待kill 线程响应对应的信号) -
处理pthread_kill 的返回值
-
参考:
https://blog.csdn.net/vah101/article/details/40393287
pthread_cancel
要点:
* 待取消的线程内部需要设置可取消属性;
- 外部发取消命令
考虑如何释放待取消线程占用、申请的资源
参考:
http://blog.sina.com.cn/s/blog_66fb0c830100y9hb.html
对应正在执行的线程如何cancel掉
使用: pthread_testcancel
NAME
pthread_testcancel - request delivery of any pending cancellation request
SYNOPSIS
#include <pthread.h>
void pthread_testcancel(void);
Compile and link with -pthread.
DESCRIPTION
Calling pthread_testcancel() creates a cancellation point within the calling thread,
so that a thread that is otherwise executing code that contains no cancellation
points will respond to a cancellation request.
If cancelability is disabled (using pthread_setcancelstate(3)), or no cancellation
request is pending, then a call to pthread_cancel() has no effect.
RETURN VALUE
This function does not return a value. If the calling thread is canceled as a con-
sequence of a call to this function, then the function does not return.
参考https://www.cnblogs.com/tianzeng/p/9195091.html