线程

http://www.cnblogs.com/skynet/archive/2010/10/30/1865267.html 
pthread_exit($num) 指定返回值,其他线程通过pthread_join()来获得
return 直接返回
exit 退出进程


临界区,临界区内的代码不会被中断打扰,具有原子性质


https://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/
线程函数表
线程
创建 pthread_create()
退出 pthread_exit()
等待 pthread_join()


互斥锁
创建 pthread_mutex_init()
销毁 pthread_mutex_destroy()
加锁 pthread_mutex_lock()
解锁 pthread_mutex_unlock()


条件
创建 pthread_cond_init()
销毁 pthread_cond_destroy()
触发 pthread_cond_signal()
广播 pthread_cond_broadcast()
等待 pthread_cond_wait()/pthread_cond_timedwait()


尽量设置recursive属性初始化互斥锁
pthread_mutex_t *mutex = new pthread_mutex_t
pthread_mutexattr_t mutexattr //= new pthread_mutexattr
pthread_mutexattr_init(&mutexattr)
pthread_mutexattr_settype(&mutexattr, pthread_MUTEX_RECURSIVE_NP) //pthread_MUTEXATTR_RECURSIVE)
pthread_mutex_init(mutex, &mutexattr) //&mutex, mutexattr)
pthread_mutexattr_destroy(&mutexattr)
pthread_mutex_lock(mutex)
pthread_mutex_unlock(mutex)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值