pthreads的pthread_cleanup_push和pop函数
读apue的11.5节的代码11.5遇到问题,stackoverflow解答:
https://stackoverflow.com/questions/14421688/pthread-cleanup-pop-with-argument-0
did I get pthread_cleanup_pop wrong?
No, you didn't.
The reason your code executed cleanup handlers, is that your control never reaches pthread_cleanup_pop(0). Instead, you always execute return in thr_fn1, and pthread_exit in thr_fn2.
Try creating the threads with pthread_create(&tid1, NULL, thr_fn1, (void *)0); instead of 1. When I do that, I get (expected):
thread 1 start
thread 1 push complete
thread 2 start
thread 2 push complete
thread 1 exit code 1
thread 2 exit code 2
posted on 2018-03-12 22:11 CreatorKou 阅读(130) 评论(0) 收藏 举报
浙公网安备 33010602011771号