初探线程02

1.线程的取消

NAME
    pthread_cancel - send a cancellation request to a thread

SYNOPSIS
    #include <pthread.h>

    int pthread_cancel(pthread_t thread);

①取消有两种状态,允许和不允许
②允许取消又分为
异步cancel
推迟cancel(默认) 推迟到cancel点才被响应
cancel点: posix定义的cancel点 都是可能引发阻塞的系统调用

2.pthread_setcancelstate

设置取消方式

NAME
pthread_setcancelstate, pthread_setcanceltype - set cancelability state and type

SYNOPSIS
#include <pthread.h>

int pthread_setcancelstate(int state, int *oldstate);

3.pthread_testcancel

设置一个取消点

NAME
       pthread_testcancel - request delivery of any pending cancellation request

SYNOPSIS
       #include <pthread.h>

       void pthread_testcancel(void);

4.线程分离

NAME
       pthread_detach - detach a thread

SYNOPSIS
       #include <pthread.h>

       int pthread_detach(pthread_t thread);

分离一个线程,与之毫无关系,如果调用join会报错

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值