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

被折叠的 条评论
为什么被折叠?



