pthread conditions and process termination

后端 未结 3 1274
长情又很酷
长情又很酷 2021-01-12 14:55

I have a process-shared pthread condition (with associated mutex). What would happen if a process waiting on this condition (using pthread_cond_wait() or pthread_cond_timed

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 15:30

    The source code of pthread_cond_destroy says the following:

    Thus, we can assume that all waiters that are still accessing the condvar have been woken. We wait until they have confirmed to have woken up by decrementing __wrefs.

    So we can simply reset __wrefs to zero before pthread_cond_destroy:

    c->c.__data.__wrefs = 0;
    r = pthread_cond_destroy(&c->c);
    

    I ran you sample with this change and P1 completes with no hang.

    Note that before this commit __wrefs was called __nwaiters.

提交回复
热议问题