1 .\" Copyright (c) 2004 Michael Telahun Makonnen
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nm pthread_barrier_destroy , pthread_barrier_init , pthread_barrier_wait
32 .Nd "destroy, initialize or wait on a barrier object"
39 .Fn pthread_barrier_destroy "pthread_barrier_t *barrier"
41 .Fn pthread_barrier_init "pthread_barrier_t *barrier" "const pthread_barrierattr_t *attr" "unsigned count"
43 .Fn pthread_barrier_wait "pthread_barrier_t *barrier"
46 .Fn pthread_barrier_init
47 function will initialize
49 with attributes specified in
53 with default attributes.
54 The number of threads that must call
55 .Fn pthread_barrier_wait
56 before any of the waiting threads can be
57 released is specified by
60 .Fn pthread_barrier_destroy
63 and release any resources that may have been allocated on its behalf.
66 .Fn pthread_barrier_wait
67 function will synchronize calling threads at
69 The threads will be blocked from
70 making further progress until
71 a sufficient number of threads calls this function.
72 The number of threads that must call it before
73 any of them will be released is determined by the
76 .Fn pthread_barrier_init .
77 Once the threads have been released the barrier will be reset.
78 .Sh IMPLEMENTATION NOTES
84 .Dv PTHREAD_BARRIER_SERIAL_THREAD
86 always be returned by the last thread to reach the barrier.
90 .Fn pthread_barrier_destroy
92 .Fn pthread_barrier_init
94 Otherwise, an error number will be returned to indicate the error.
96 .Fn pthread_barrier_wait
97 is successful, all but one of the threads will return zero.
98 That one thread will return
99 .Dv PTHREAD_BARRIER_SERIAL_THREAD .
100 Otherwise, an error number will be returned to indicate the error.
102 None of these functions will return
106 .Fn pthread_barrier_destroy
107 function will fail if:
110 An attempt was made to destroy
116 .Fn pthread_barrier_destroy
118 .Fn pthread_barrier_wait
119 functions may fail if:
122 The value specified by
128 .Fn pthread_barrier_init
129 function will fail if:
132 The system lacks resources,
139 argument is less than 1.
141 Insufficient memory to initialize
145 .Xr pthread_barrierattr 3
148 .Fn pthread_barrier_destroy ,
149 .Fn pthread_barrier_init
151 .Fn pthread_barrier_wait
152 functions first appeared in