2010-07-09 22:07:20 +04:00
|
|
|
.\" $NetBSD: pthread_barrier.3,v 1.4 2010/07/09 18:07:20 jruoho Exp $
|
2003-06-04 01:31:36 +04:00
|
|
|
.\"
|
2010-07-08 23:20:16 +04:00
|
|
|
.\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
|
2003-06-04 01:31:36 +04:00
|
|
|
.\" All rights reserved.
|
2010-07-08 23:20:16 +04:00
|
|
|
.\"
|
2003-06-04 01:31:36 +04:00
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2010-07-08 23:20:16 +04:00
|
|
|
.\"
|
2003-06-04 01:31:36 +04:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
2010-07-08 23:20:16 +04:00
|
|
|
.\" ----------------------------------------------------------------------------
|
|
|
|
.Dd July 8, 2010
|
|
|
|
.Dt PTHREAD_BARRIER 3
|
2003-06-04 01:31:36 +04:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2010-07-08 23:20:16 +04:00
|
|
|
.Nm pthread_barrier
|
|
|
|
.Nd barrier interface
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libpthread
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In pthread.h
|
|
|
|
.Ft int
|
2010-07-08 23:20:16 +04:00
|
|
|
.Fn pthread_barrier_init "pthread_barrier_t * restrict barrier" \
|
|
|
|
"const pthread_barrierattr_t * restrict attr" "unsigned int count"
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_barrier_destroy "pthread_barrier_t *barrier"
|
|
|
|
.Ft int
|
|
|
|
.Fn pthread_barrier_wait "pthread_barrier_t *barrier"
|
|
|
|
.\" ----------------------------------------------------------------------------
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn pthread_barrier_init
|
2010-07-09 00:59:43 +04:00
|
|
|
function creates a new barrier with attributes
|
2003-07-04 12:36:06 +04:00
|
|
|
.Fa attr
|
|
|
|
and
|
2003-06-04 01:31:36 +04:00
|
|
|
.Fa count .
|
2003-07-04 12:36:06 +04:00
|
|
|
The
|
2003-06-04 01:31:36 +04:00
|
|
|
.Fa count
|
2010-07-09 00:59:43 +04:00
|
|
|
parameter indicates the number of threads
|
|
|
|
which will participate in the barrier.
|
|
|
|
The
|
|
|
|
.Xr pthread_barrierattr_init 3
|
|
|
|
function may be used to specify the attributes supplied in
|
|
|
|
.Fa attr .
|
2003-06-04 01:31:36 +04:00
|
|
|
If
|
|
|
|
.Fa attr
|
2010-07-09 00:59:43 +04:00
|
|
|
is
|
|
|
|
.Dv NULL ,
|
|
|
|
the default attributes are used.
|
2003-06-04 01:31:36 +04:00
|
|
|
Barriers are most commonly used in the decomposition of parallel loops.
|
2010-07-08 23:20:16 +04:00
|
|
|
.Pp
|
|
|
|
.\" -----
|
|
|
|
The
|
|
|
|
.Fn pthread_barrier_destroy
|
|
|
|
function causes the resources allocated to
|
|
|
|
.Fa barrier
|
|
|
|
to be released.
|
|
|
|
No threads should be blocked on
|
|
|
|
.Fa barrier .
|
|
|
|
.Pp
|
|
|
|
.\" -----
|
|
|
|
The
|
|
|
|
.Fn pthread_barrier_wait
|
|
|
|
function causes the current thread to wait on the barrier specified.
|
|
|
|
Once as many threads as specified by the
|
|
|
|
.Fa count
|
|
|
|
parameter to the corresponding
|
|
|
|
.Fn pthread_barrier_init
|
|
|
|
call have called
|
|
|
|
.Fn pthread_barrier_wait ,
|
|
|
|
all threads will wake up, return from their respective
|
|
|
|
.Fn pthread_barrier_wait
|
|
|
|
calls and continue execution.
|
|
|
|
.\" ----------------------------------------------------------------------------
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
If successful,
|
|
|
|
.Fn pthread_barrier_init
|
|
|
|
will return zero and put the new barrier id into
|
|
|
|
.Fa barrier ,
|
|
|
|
otherwise an error number will be returned to indicate the error.
|
2010-07-08 23:20:16 +04:00
|
|
|
.Pp
|
|
|
|
.\" -----
|
|
|
|
If successful,
|
|
|
|
.Fn pthread_barrier_destroy
|
|
|
|
will return zero.
|
|
|
|
Otherwise an error value will be returned.
|
|
|
|
.Pp
|
|
|
|
.\" -----
|
|
|
|
If successful,
|
|
|
|
.Fn pthread_barrier_wait
|
|
|
|
will return zero for all waiting threads except for one.
|
|
|
|
One thread will receive status
|
|
|
|
.Dv 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 barrier.
|
|
|
|
In the case of failure, an error value will be returned.
|
|
|
|
.\" ----------------------------------------------------------------------------
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh ERRORS
|
2010-07-09 22:07:20 +04:00
|
|
|
The
|
2003-06-04 01:31:36 +04:00
|
|
|
.Fn pthread_barrier_init
|
2010-07-09 22:07:20 +04:00
|
|
|
function may fail if:
|
2003-06-04 01:31:36 +04:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The value specified by
|
|
|
|
.Fa count
|
2010-07-08 23:20:16 +04:00
|
|
|
is zero or
|
|
|
|
.Fa attr
|
|
|
|
is invalid.
|
2003-06-04 01:31:36 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2010-07-08 23:20:16 +04:00
|
|
|
.\" -----
|
2010-07-09 22:07:20 +04:00
|
|
|
The
|
2010-07-08 23:20:16 +04:00
|
|
|
.Fn pthread_barrier_destroy
|
2010-07-09 22:07:20 +04:00
|
|
|
function may fail if:
|
2003-06-04 01:31:36 +04:00
|
|
|
.Bl -tag -width Er
|
2008-05-26 12:43:57 +04:00
|
|
|
.It Bq Er EBUSY
|
2010-07-08 23:20:16 +04:00
|
|
|
The
|
|
|
|
.Fa barrier
|
|
|
|
still has active threads associated with it.
|
2003-06-04 01:31:36 +04:00
|
|
|
.It Bq Er EINVAL
|
|
|
|
The value specified by
|
2010-07-08 23:20:16 +04:00
|
|
|
.Fa barrier
|
2003-06-04 01:31:36 +04:00
|
|
|
is invalid.
|
|
|
|
.El
|
2010-07-08 23:20:16 +04:00
|
|
|
.Pp
|
|
|
|
.\" -----
|
2010-07-09 22:07:20 +04:00
|
|
|
The
|
2010-07-08 23:20:16 +04:00
|
|
|
.Fn pthread_barrier_wait
|
2010-07-09 22:07:20 +04:00
|
|
|
function may fail if:
|
2010-07-08 23:20:16 +04:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The value specified by
|
|
|
|
.Fa barrier
|
|
|
|
is invalid.
|
|
|
|
.El
|
2010-07-09 22:07:20 +04:00
|
|
|
.\" ---------------------------------------------------------------------------
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh SEE ALSO
|
2010-07-08 23:20:16 +04:00
|
|
|
.Xr pthread_barrierattr 3 ,
|
2010-07-09 01:33:38 +04:00
|
|
|
.Xr pthread_cond 3 ,
|
2010-07-09 22:07:20 +04:00
|
|
|
.Xr pthread_mutex 3
|
2003-06-04 01:31:36 +04:00
|
|
|
.Sh STANDARDS
|
2010-07-08 23:20:16 +04:00
|
|
|
These functions conform to
|
2003-06-04 01:31:36 +04:00
|
|
|
.St -p1003.1-2001 .
|