多线程编程

#include <pthread.h>
int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*fun)(void *), void *arg);
/*
 * 创建线程
 * @tid —— 线程id的类型为pthread_t,成功创建后的线程由tid返回。
 * @attr —— 指定创建线程的属性,如线程优先级、初试栈大小、是否为守护进程。一般使用NULL来指定默认值。
 * @func —— 通过func来指定创建线程后,所有执行的函数。
 * @arg —— 线程执行函数的参数
 * return —— 创建成功返回0.
 */

int pthread_join(pthread_t *tid, void **status);
/*
 * 等待线程tid退出
 * @tid —— 指定要等待的线程ID
 * @status —— 如果不为NULL,那么线程的返回值存储在status指向的空间中
 * return —— 执行成功返回0
 */

void pthread_exit(void *status)
/*
 * 终止线程
 * @status —— 指定线程终止的返回值
 */

pthread_t pthread_self(void)
/*
 * 获取当前线程的ID
 */

int pthread_equal(pthread_t tid1, pthread_t tid2);
/*
 * 比较两个线程ID 
 * 相等返回非0值, 不等返回0
 */

int pthread_cancel(pthead_t tid);
/*
 * 取消统一进程中的其他线程
 * 成功返回0, 失败返回错误编号
 */

int pthread_detach(pthrad_t tid);
/*
 * 指定线程变为分离状态
 * 分离状态的线程退出,将释放多有的资源,不是分离状态的线程退出后就变成了僵死线程
 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值