cmultithreadingpthreadspthread-barriers

Regarding PThread's and PThread Barriers


I'm writing an SMT program, and I'm trying to workaround an interesting problem.

I need all my functions to exit together, however some of the threads get stuck at barriers, even when i don't want them to.

My question is: what happens when i delete a barrier? Do threads stuck at the barrier release? Is there a way to signal a release to a certain barrier, even if the number of threads at the barrier hasn't been achieved?

Thanks


Solution

  • It's not legal to call pthread_barrier_destroy() if there's any threads blocked on the barrier.

    When your thread decides to exit early in a situation where other threads could be waiting on it at a barrier, it should call pthread_barrier_wait() before exiting.