设置线程退出时的回调函数

本文详细介绍了 POSIX 线程库 (pthreads) 中的清理函数功能及使用方法。当线程结束时,可以指定一个或多个清理函数由 pthreads 库自动调用。这些函数会在线程终止时按照注册的逆序被调用。文章还说明了如何通过 API pthread_cleanup_push 和 pthread_cleanup_pop 来管理这些清理函数。

This is done by specifying one ormore functions that will be called automatically by the pthreads library whenthe thread exits, either due to its own will (e.g. calling pthread_exit()), ordue to it being canceled. When the thread terminates, its cleanup functions arecalled in the reverse order of their registration. So the the last one to beregistered is the first one to be called.


API

 

pthread_cleanup_push

add a cleanup function to the set of cleanup functions for the current thread.

pthread_cleanup_pop

removes the last function added with pthread_cleanup_push().

 

 

 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值