linux 线程

因为pthread的库不是linux系统的库,所以在进行编译的时候要加上-lpthread


pthread.h


int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);//创建线程


参数thread:线程创建时,这个指针指向变量中被写入一个标识符,标识符来引用新线程
参数attr:用于设置线程的属性
参数start_routine:指定线程将要执行的函数
参数arg:要执行函数传递的参数






void pthread_exit(void *retval); //线程退出


retval:线程退出返回值的指针






int pthread_join(pthread_t th, void **thread_return);//阻塞调用线程,直到指定的线程终止


参数th:指定将要等待的线程
参数thread_return:指向线程的返回值




pthread_mutex_t count_lock = PTHREAD_MUTEX_INITIALIZER;
int pthread_mutex_lock(pthread_mutex_t *mutex); //加锁
int pthread_mutex_unlock(pthread_mutex_t *mutex); //解锁
int pthread_mutex_destroy(pthread_mutex_t *mutex); //清理






pthread_t pthread_self(void); //获取调用线程的标识
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值