Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pthread_barrier_init(3) [netbsd man page]

PTHREAD_BARRIER(3)					   BSD Library Functions Manual 					PTHREAD_BARRIER(3)

NAME
pthread_barrier -- barrier interface LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_barrier_init(pthread_barrier_t * restrict barrier, const pthread_barrierattr_t * restrict attr, unsigned int count); int pthread_barrier_destroy(pthread_barrier_t *barrier); int pthread_barrier_wait(pthread_barrier_t *barrier); DESCRIPTION
The pthread_barrier_init() function creates a new barrier with attributes attr and count. The count parameter indicates the number of threads which will participate in the barrier. The pthread_barrierattr_init(3) function may be used to specify the attributes supplied in attr. If attr is NULL, the default attributes are used. Barriers are most commonly used in the decomposition of parallel loops. The pthread_barrier_destroy() function causes the resources allocated to barrier to be released. No threads should be blocked on barrier. The pthread_barrier_wait() function causes the current thread to wait on the barrier specified. Once as many threads as specified by the count parameter to the corresponding pthread_barrier_init() call have called pthread_barrier_wait(), all threads will wake up, return from their respective pthread_barrier_wait() calls and continue execution. RETURN VALUES
If successful, pthread_barrier_init() will return zero and put the new barrier id into barrier, otherwise an error number will be returned to indicate the error. If successful, pthread_barrier_destroy() will return zero. Otherwise an error value will be returned. If successful, pthread_barrier_wait() will return zero for all waiting threads except for one. One thread will receive status PTHREAD_BARRIER_SERIAL_THREAD, which is intended to indicate that this thread may be used to update shared data. It is the responsibility of this thread to insure the visibility and atomicity of any updates to shared data with respect to the other threads participating in the bar- rier. In the case of failure, an error value will be returned. ERRORS
The pthread_barrier_init() function may fail if: [EINVAL] The value specified by count is zero or attr is invalid. The pthread_barrier_destroy() function may fail if: [EBUSY] The barrier still has active threads associated with it. [EINVAL] The value specified by barrier is invalid. The pthread_barrier_wait() function may fail if: [EINVAL] The value specified by barrier is invalid. SEE ALSO
pthread_barrierattr(3), pthread_cond(3), pthread_mutex(3) STANDARDS
These functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
July 8, 2010 BSD

Check Out this Related Man Page

pthread_barrier_destroy(3C)				   Standard C Library Functions 			       pthread_barrier_destroy(3C)

NAME
pthread_barrier_destroy, pthread_barrier_init - destroy and initialize a barrier object SYNOPSIS
cc -mt [ flag... ] file... [ library... ] #include <pthread.h> int pthread_barrier_destroy(pthread_barrier_t *barrier); int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *restrict attr, unsigned count); DESCRIPTION
The pthread_barrier_destroy() function destroys the barrier referenced by barrier and releases any resources used by the barrier. The effect of subsequent use of the barrier is undefined until the barrier is reinitialized by another call to pthread_barrier_init(). An implementation can use this function to set barrier to an invalid value. The results are undefined if pthread_barrier_destroy() is called when any thread is blocked on the barrier, or if this function is called with an uninitialized barrier. The pthread_barrier_init() function allocates any resources required to use the barrier referenced by barrier and initializes the barrier with attributes referenced by attr. If attr is NULL, the default barrier attributes are used; the effect is the same as passing the address of a default barrier attributes object. The results are undefined if pthread_barrier_init() is called when any thread is blocked on the barrier (that is, has not returned from the pthread_barrier_wait(3C) call). The results are undefined if a barrier is used without first being initialized. The results are undefined if pthread_barrier_init() is called specifying an already initialized barrier. The count argument specifies the number of threads that must call pthread_barrier_wait() before any of them successfully return from the call. The value specified by count must be greater than 0. If the pthread_barrier_init() function fails, the barrier is not initialized and the contents of barrier are undefined. Only the object referenced by barrier can be used for performing synchronization. The result of referring to copies of that object in calls to pthread_barrier_destroy() or pthread_barrier_wait() is undefined. RETURN VALUES
Upon successful completion, these functions returns 0. Otherwise, an error number is returned to indicate the error. ERRORS
The pthread_barrier_init() function will fail if: EAGAIN The system lacks the necessary resources to initialize another barrier. EINVAL The value specified by count is equal to 0. ENOMEM Insufficient memory exists to initialize the barrier. The pthread_barrier_init() function may fail if: EBUSY The implementation has detected an attempt to destroy a barrier while it is in use (for example, while being used in a pthread_barrier_wait() call) by another thread. EINVAL The value specified by attr is invalid. The pthread_barrier_destroy() function may fail if: EBUSY The implementation has detected an attempt to destroy a barrier while it is in use (for example, while being used in a pthread_barrier_wait() call) by another thread. EINVAL The value specified by barrier is invalid. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
pthread_barrier_wait(3C), attributes(5), standards(5) SunOS 5.11 30 Jan 2004 pthread_barrier_destroy(3C)
Man Page