2 Copyright (C) 2000-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
33 pthread_barrier_t
*barrier
= arg
;
36 ret
= pthread_barrier_wait (barrier
);
37 printf ("%d ", pthread_self ());
42 main (int argc
, char **argv
)
44 pthread_barrierattr_t attr
;
45 pthread_barrier_t barrier
;
49 pthread_t tid
[THREADS
];
53 err
= pthread_barrierattr_init (&attr
);
55 error (1, err
, "pthread_barrierattr_init");
57 err
= pthread_barrierattr_getpshared (&attr
, &i
);
59 error (1, err
, "pthread_barrierattr_getpshared");
60 assert (i
== PTHREAD_PROCESS_PRIVATE
|| i
== PTHREAD_PROCESS_SHARED
);
62 err
= pthread_barrierattr_setpshared (&attr
, PTHREAD_PROCESS_PRIVATE
);
64 error (1, err
, "pthread_barrierattr_setpshared");
66 err
= pthread_barrier_init (&barrier
, &attr
, THREADS
+ 1);
68 error (1, err
, "pthread_barrier_init");
70 for (j
= 0; j
< WAITS
; j
++)
73 for (i
= 0; i
< THREADS
; i
++)
75 err
= pthread_create (&tid
[i
], 0, dowait
, &barrier
);
77 error (1, err
, "pthread_create (%d)", i
);
80 printf ("Manager will now call pthread_barrier_wait.\n");
83 = pthread_barrier_wait (&barrier
) == PTHREAD_BARRIER_SERIAL_THREAD
86 for (i
= THREADS
- 1; i
>= 0; i
--)
89 err
= pthread_join (tid
[i
], &ret
);
91 error (1, err
, "pthread_join");
98 case PTHREAD_BARRIER_SERIAL_THREAD
:
103 assert (!"Unknown value returned from pthread_barrier_wait.");
110 assert (havesyncs
== 1);