pthread_cleanup_push() & pthread_cleanup_pop()




.

pthread_cleanup_push() 一般用于线程结束时回调一些函数,push顾名思义向stack中压入一个函数。通过宏展开实现,展开后带有一个{
pthread_cleanup_pop()  一般就设成0了,用于和push匹配,宏展开后带有},如果不一一对应,编译一定会报错,因为{}不匹配。

stack内的函数只有在以下条件下会被调用

  • 线程通过pthread_exit()函数退出
  • 线程被pthread_cancel()取消
  • pthread_cleanup_pop(int execute)时,execute传了一个非0值
phread_join(pthread_t tid, void **value_ptr)中,value_ptr传回被join的线程的返回值,该返回值通过
pthread_exit(void *return_value)的参数来传递
  • 线程通过pthread_exit()函数退出
  • 线程被pthread_cancel()取消
  • pthread_cleanup_pop(int execute)时,execute传了一个非0值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值