pthread_cleanup_pop with argument 0?

前端 未结 1 790
离开以前
离开以前 2021-01-13 15:21

I am studying thread in APUE book 2e

I thought pthread_cleanup_pop functions is for setting the pushed function by pthread_cleanup_push() to be executed or not. So i

1条回答
  •  孤城傲影
    2021-01-13 16:25

    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
    

    0 讨论(0)
提交回复
热议问题