《APUE》:线程清理处理程序

2014-11-24 10:19:17 · 作者: · 浏览: 0

相关链接


程序简介:这个程序演示了如何使用线程清理处理程序,并解释了其中涉及的清理机制。


运行示例(红色字体的为输入):


thread 1 start
thread 1 push complete
thread 2 start
thread 2 push complete
cleanup: thread 2 second handler
cleanup: thread 2 first handler
thread 1 exit code
thread 2 exit code


注解:
1:两个子线程都正确启动和退出了
2:如果线程是通过从它的启动线程中返回而终止的话,那么它的清理处理函数就不会被调用。
3:必须把pthread_cleanup_push的调用和pthread_cleanup_pop的调用匹配起来,否则程序通不过编译。