- NAME
- new_barrier - allocate a new barrier
delete_barrier - delete a barrier
barrier_init - initialize a barrier
barrier_check - wait until all other threads have reached the barrier
- SYNOPSIS
- #include <mthread.h>
barr_p new_barrier(int n);
void delete_barrier(barr_p bp);
barr_p barrier_init(barr_p bp, int n);
void barrier_check(barr_p bp);
- DESCRIPTION
- Barriers are usually used when it should be assured that a couple of
threads have reached at a specific point in their computation. All, except
the last thread reaching the barrier will be blocked. If the last thread
arrives it deblockes all the other threads.
new_barrier(int n) allocates a new barrier and initializes it for
use by n threads.
delete_barrier() deletes a barrier that has been allocated by
new_barrier().
barrier_init() can be used to reinitialize a barrier that has
already been allocated. This is necessary if the barrier will be used
with a different number of threads than it has been created for.
barrier_check() is used to notice the calling thread's arrival to
the barrier. If it's not the last thread it will get blocked. Otherwise it
will unblock all other threads and reinitialize the barrier for its next
use.
- RETURN VALUES
- Upon successful completion both new_barrier() and barrier_init() return
with a valid barrier handle. Otherwise, a null handle will be returned and merrno
set to indicate the error.
- ERRORS
- new_barrier() will fail if one of the following is true:
- [MENOMEM] there is unsufficient memory to allocate the barrier
- [MEVALUE] the number of threads must be greater than 1
barrier_init() will fail if one of the following is true:
- [MEVALUE] the number of threads must be greater than 1
- SEE ALSO
- mthreads(3),
cond(3)
mutex(3)
semaphore(3)