xref: /freebsd/share/man/man3/pthread_barrier_destroy.3 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1.\" Copyright (c) 2004 Michael Telahun Makonnen
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
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.
12.\"
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
23.\" SUCH DAMAGE.
24.\"
25.Dd August 17, 2018
26.Dt PTHREAD_BARRIER 3
27.Os
28.Sh NAME
29.Nm pthread_barrier_destroy , pthread_barrier_init , pthread_barrier_wait
30.Nd "destroy, initialize or wait on a barrier object"
31.Sh LIBRARY
32.Lb libpthread
33.Sh SYNOPSIS
34.In pthread.h
35.Ft int
36.Fn pthread_barrier_destroy "pthread_barrier_t *barrier"
37.Ft int
38.Fn pthread_barrier_init "pthread_barrier_t *restrict barrier" "const pthread_barrierattr_t *attr" "unsigned count"
39.Ft int
40.Fn pthread_barrier_wait "pthread_barrier_t *barrier"
41.Sh DESCRIPTION
42The
43.Fn pthread_barrier_init
44function will initialize
45.Fa barrier
46with attributes specified in
47.Fa attr ,
48or if it is
49.Dv NULL ,
50with default attributes.
51The number of threads that must call
52.Fn pthread_barrier_wait
53before any of the waiting threads can be
54released is specified by
55.Fa count .
56The
57.Fn pthread_barrier_destroy
58function will destroy
59.Fa barrier
60and release any resources that may have been allocated on its behalf.
61.Pp
62The
63.Fn pthread_barrier_wait
64function will synchronize calling threads at
65.Fa barrier .
66The threads will be blocked from
67making further progress until
68a sufficient number of threads calls this function.
69The number of threads that must call it before
70any of them will be released is determined by the
71.Fa count
72argument to
73.Fn pthread_barrier_init .
74Once the threads have been released the barrier will be reset.
75.Sh IMPLEMENTATION NOTES
76In
77.Lb libthr
78the
79.Dv PTHREAD_BARRIER_SERIAL_THREAD
80return value will
81always be returned by the last thread to reach the barrier.
82.Sh RETURN VALUES
83If successful,
84both
85.Fn pthread_barrier_destroy
86and
87.Fn pthread_barrier_init
88will return zero.
89Otherwise, an error number will be returned to indicate the error.
90If the call to
91.Fn pthread_barrier_wait
92is successful, all but one of the threads will return zero.
93That one thread will return
94.Dv PTHREAD_BARRIER_SERIAL_THREAD .
95Otherwise, an error number will be returned to indicate the error.
96.Pp
97None of these functions will return
98.Er EINTR .
99.Sh ERRORS
100The
101.Fn pthread_barrier_destroy
102function will fail if:
103.Bl -tag -width Er
104.It Bq Er EBUSY
105An attempt was made to destroy
106.Fa barrier
107while it was in use.
108.El
109.Pp
110The
111.Fn pthread_barrier_destroy
112and
113.Fn pthread_barrier_wait
114functions may fail if:
115.Bl -tag -width Er
116.It Bq Er EINVAL
117The value specified by
118.Fa barrier
119is invalid.
120.El
121.Pp
122The
123.Fn pthread_barrier_init
124function will fail if:
125.Bl -tag -width Er
126.It Bq Er EAGAIN
127The system lacks resources,
128other than memory,
129to initialize
130.Fa barrier .
131.It Bq Er EINVAL
132The
133.Fa count
134argument is less than 1.
135.It Bq Er ENOMEM
136Insufficient memory to initialize
137.Fa barrier .
138.El
139.Sh SEE ALSO
140.Xr pthread_barrierattr 3
141.Sh HISTORY
142The
143.Fn pthread_barrier_destroy ,
144.Fn pthread_barrier_init
145and
146.Fn pthread_barrier_wait
147functions first appeared in
148.Lb libkse
149in
150.Fx 5.2 ,
151and in
152.Lb libthr
153in
154.Fx 5.3 .
155