1 /* Copyright (C) 2003-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
21 #include <semaphore.h>
28 static pthread_t th
[N
];
31 static int do_test (void);
33 #define TEST_FUNCTION do_test ()
34 #include "../test-skeleton.c"
40 if (th[n] != pthread_self ()) \
42 write_message ("wrong callback\n"); \
56 static void (*cbs
[]) (void) =
58 cb0
, cb1
, cb2
, cb3
, cb4
, cb5
, cb6
, cb7
, cb8
, cb9
62 static __thread
void (*fp
) (void) __attribute__ ((tls_model ("local-exec")));
68 #define THE_SIG SIGUSR1
74 write_message ("wrong signal\n");
80 if (sem_post (&s
) != 0)
82 write_message ("sem_post failed\n");
88 static pthread_barrier_t b
;
90 #define TOTAL_SIGS 1000
99 pthread_barrier_wait (&b
);
101 pthread_barrier_wait (&b
);
103 if (nsigs
!= TOTAL_SIGS
)
105 puts ("barrier_wait prematurely returns");
116 if (pthread_barrier_init (&b
, NULL
, N
+ 1) != 0)
118 puts ("barrier_init failed");
122 if (sem_init (&s
, 0, 0) != 0)
124 puts ("sem_init failed");
129 sa
.sa_handler
= handler
;
130 sigemptyset (&sa
.sa_mask
);
132 if (sigaction (THE_SIG
, &sa
, NULL
) != 0)
134 puts ("sigaction failed");
140 if (pthread_attr_init (&a
) != 0)
142 puts ("attr_init failed");
146 if (pthread_attr_setstacksize (&a
, 1 * 1024 * 1024) != 0)
148 puts ("attr_setstacksize failed");
153 for (i
= 0; i
< N
; ++i
)
154 if (pthread_create (&th
[i
], &a
, tf
, cbs
[i
]) != 0)
156 puts ("pthread_create failed");
160 if (pthread_attr_destroy (&a
) != 0)
162 puts ("attr_destroy failed");
166 pthread_barrier_wait (&b
);
170 sigaddset (&ss
, THE_SIG
);
171 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
173 puts ("pthread_sigmask failed");
177 /* Start sending signals. */
178 for (i
= 0; i
< TOTAL_SIGS
; ++i
)
180 if (kill (getpid (), THE_SIG
) != 0)
182 puts ("kill failed");
186 if (TEMP_FAILURE_RETRY (sem_wait (&s
)) != 0)
188 puts ("sem_wait failed");
195 pthread_barrier_wait (&b
);
197 for (i
= 0; i
< N
; ++i
)
198 if (pthread_join (th
[i
], NULL
) != 0)
200 puts ("join failed");