pthread/ Linux多线程接口

多线程编译编译需要添加-lpthread

//线程的创建  
int pthread_create(pthread_t *tid, const pthread_arrt_t* attr,  
                    void*(*start_routine)(void *), void* arg);  
//等待线程的结束,非分离的线程在结束后只有执行join才会释放全部资源  
int pthread_join(pthread_t thread, void **retval);
//线程离开时的返回值(必须为malloc或者全局变量)  
void pthread_exit(void * retval);
//分离线程,被分离的线程在结束后自动释放所有资源  
int pthread_detach(pthread_t tid);
//多线程的交互--互斥量和自旋锁  
//互斥量 
//互斥量申请
int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a);
//互斥量加锁
int pthread_mutex_lock(pthread_mutex_t *m);
//互斥量释放解锁
int pthread_mutex_unlock(pthread_mutex_t *m);
//互斥量尝试加锁,非堵塞
int pthread_mutex_trylock(pthread_mutex_t *m);
//互斥量释放
int pthread_mutex_destroy(pthread_mutex_t *m); 
//自旋锁  
pthread_spinlock_t m_spinlock;  
//自旋锁申请
int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
//自旋锁加锁
int pthread_spin_lock(pthread_spinlock_t  *m_spinlock);  
//自旋锁释放
int pthread_spin_unlock(pthread_spinlock_t  *m_spinlock);  
//自旋锁尝试加锁,非堵塞
int pthread_spin_trylock(pthread_spinlock_t  *m_spinlock);  
//自旋锁释放
int pthread_spin_destroy(pthread_spinlock_t  *m_spinlock); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值