Home

pthreadbarriert

pthread_barrier_t, commonly referred to as a barrier in the POSIX threads (pthreads) library, is a synchronization primitive that coordinates a fixed set of threads. When a barrier is used, each participating thread must reach the barrier point and wait until all designated threads have arrived, at which point they all proceed. Barriers are reusable: after release, the barrier can be used again for subsequent rendezvous.

The typical usage involves creating a barrier with pthread_barrier_init, providing the number of threads that must

Destruction of the barrier is performed with pthread_barrier_destroy. It returns 0 on success. It may fail with

Portability and notes: Barriers are defined by POSIX, but availability and exact error semantics can vary by

reach
the
barrier.
An
optional
barrier
attribute
object
(pthread_barrierattr_t)
can
be
supplied
to
control
sharing
semantics,
such
as
whether
the
barrier
can
be
shared
across
processes
(using
PTHREAD_PROCESS_SHARED)
or
remains
private
to
the
creating
process.
After
initialization,
threads
call
pthread_barrier_wait
on
the
barrier.
When
the
required
count
arrives,
all
threads
are
unblocked.
Exactly
one
thread
may
receive
the
return
value
PTHREAD_BARRIER_SERIAL_THREAD;
the
remaining
threads
receive
0.
The
serial-thread
can
be
used
to
perform
a
small
amount
of
work
once
per
barrier
cycle
if
needed,
but
this
is
optional.
EINVAL
if
the
barrier
is
invalid
or
not
properly
initialized,
or
with
EBUSY
if
the
barrier
is
currently
in
use
by
threads
(for
example,
if
some
threads
are
still
waiting
at
the
barrier).
implementation.
Cross-process
sharing
requires
suitable
support
and
shared
memory
layout.
In
some
environments,
barriers
are
not
available
or
behave
differently
from
other
synchronization
primitives
such
as
mutexes
and
condition
variables.