summaryrefslogtreecommitdiff
path: root/lib/libpthread/pthread_barrier.3
blob: 7c8264fd148011f71c1f5cb65c79043ea6250f1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
.\" $NetBSD: pthread_barrier.3,v 1.8 2017/10/22 16:15:02 abhinav Exp $
.\"
.\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" 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.
.\"
.\" 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.
.\"
.\" ----------------------------------------------------------------------------
.Dd October 22, 2017
.Dt PTHREAD_BARRIER 3
.Os
.Sh NAME
.Nm pthread_barrier ,
.Nm pthread_barrier_init ,
.Nm pthread_barrier_destroy ,
.Nm pthread_barrier_wait
.Nd barrier interface
.Sh LIBRARY
.Lb libpthread
.Sh SYNOPSIS
.In pthread.h
.Ft int
.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"
.\" ----------------------------------------------------------------------------
.Sh DESCRIPTION
The
.Fn pthread_barrier_init
function creates a new barrier with attributes
.Fa attr
and
.Fa count .
The
.Fa count
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 .
If
.Fa attr
is
.Dv NULL ,
the default attributes are used.
Barriers are most commonly used in the decomposition of parallel loops.
.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.
.\" -----
.\" ----------------------------------------------------------------------------
.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.
.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.
.\" ----------------------------------------------------------------------------
.Sh ERRORS
The
.Fn pthread_barrier_init
function may fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The value specified by
.Fa count
is zero or
.Fa attr
is invalid.
.El
.Pp
.\" -----
The
.Fn pthread_barrier_destroy
function may fail if:
.Bl -tag -width Er
.It Bq Er EBUSY
The
.Fa barrier
still has active threads associated with it.
.It Bq Er EINVAL
The value specified by
.Fa barrier
is invalid.
.El
.Pp
.\" -----
The
.Fn pthread_barrier_wait
function may fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The value specified by
.Fa barrier
is invalid.
.El
.\" ---------------------------------------------------------------------------
.Sh SEE ALSO
.Xr pthread_barrierattr 3 ,
.Xr pthread_cond 3 ,
.Xr pthread_mutex 3
.Sh STANDARDS
These functions conform to
.St -p1003.1-2001 .