![]() |
![]() |
![]() |
Synchronize participating threads at the barrier
#include <sync.h> int pthread_barrier_wait( pthread_barrier_t * barrier );
libc
The pthread_barrier_wait() function synchronizes participating threads at the barrier referenced by barrier. The calling thread blocks (that is, doesn't return from the pthread_barrier_wait() call) until the required number of threads have called pthread_barrier_wait() specifying the barrier.
When the required number of threads have called pthread_barrier_wait() specifying the barrier, the constant BARRIER_SERIAL_THREAD is returned to one unspecified thread and zero is returned to each of the remaining threads. At this point, the barrier is reset to the state it occupied as a result of the most recent barrier_init() function that referenced it.
The constant BARRIER_SERIAL_THREAD is defined in <pthread.h> and its value is distinct from any other value returned by pthread_barrier_wait().
If a signal is delivered to a thread blocked on a barrier, on return from the signal handler, the thread resumes waiting at the barrier as if it wasn't interrupted.
BARRIER_SERIAL_THREAD for a single (arbitrary) thread synchronized at the barrier and zero for each of the other threads; otherwise, an error number is returned:
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pthread_barrier_destroy(), pthread_barrier_init()
![]() |
![]() |
![]() |