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
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.