pthread_cancel 和pthread_kill的区别

来源:互联网 发布:淘宝小背包 编辑:程序博客网 时间:2024/05/21 18:35

1、int pthread_kill(pthread_t thread, int sig);

功能是向指定线程发送信号,信号为0时用于检查此线程ID的线程是否存活。

pthread_kill的返回值:
成功:0
线程不存在:ESRCH
信号不合法:EINVAL

2、pthread_cancel(pthread_t thread);

功能是给线程发送取消信号,使线程从取消点退出。

取消点:

根据POSIX标准,pthread_join()pthread_testcancel()pthread_cond_wait()pthread_cond_timedwait()sem_wait()sigwait()等函数以及read()write()等会引起阻塞的系统调用都是Cancelation-point,而其他pthread函数都不会引起Cancelation动作。

pthread_testcancel()也是一个取消点


http://www.cnblogs.com/mydomain/archive/2011/08/15/2139850.html

http://blog.csdn.net/kaiwii/article/details/7719011

原创粉丝点击