It depends a lot on how and why they expire.
The barrier doesn't care where pthread_barrier_wait () is called on it, so if it is a programmed expiration, then just call wait on it at that point. The barrier count is reduced, and when the threads are freed, you can perform a normal error check, and then immediately call pthread_exit or something else. Including pthread_wait in a separate function can simplify the situation.
if (must_die)
{
do_barrier_wait();
pthread_exit(NULL);
}
If the threads expire because they are killed or canceled, life becomes more complicated, and you are probably heading to the monumental territory of hacking, and perhaps you should reconsider the design.
source
share