1 /* Copyright (C) 2003-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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 <http://www.gnu.org/licenses/>. */
22 #include <semaphore.h>
29 static pthread_t th
[N
];
32 static int do_test (void);
34 #define TEST_FUNCTION do_test ()
35 #include "../test-skeleton.c"
41 if (th[n] != pthread_self ()) \
43 write_message ("wrong callback\n"); \
57 static void (*cbs
[]) (void) =
59 cb0
, cb1
, cb2
, cb3
, cb4
, cb5
, cb6
, cb7
, cb8
, cb9
63 static __thread
void (*fp
) (void) __attribute__ ((tls_model ("local-exec")));
69 #define THE_SIG SIGUSR1
75 write_message ("wrong signal\n");
81 if (sem_post (&s
) != 0)
83 write_message ("sem_post failed\n");
89 static pthread_barrier_t b
;
91 #define TOTAL_SIGS 1000
100 pthread_barrier_wait (&b
);
102 pthread_barrier_wait (&b
);
104 if (nsigs
!= TOTAL_SIGS
)
106 puts ("barrier_wait prematurely returns");
117 if (pthread_barrier_init (&b
, NULL
, N
+ 1) != 0)
119 puts ("barrier_init failed");
123 if (sem_init (&s
, 0, 0) != 0)
125 puts ("sem_init failed");
130 sa
.sa_handler
= handler
;
131 sigemptyset (&sa
.sa_mask
);
133 if (sigaction (THE_SIG
, &sa
, NULL
) != 0)
135 puts ("sigaction failed");
141 if (pthread_attr_init (&a
) != 0)
143 puts ("attr_init failed");
147 if (pthread_attr_setstacksize (&a
, 1 * 1024 * 1024) != 0)
149 puts ("attr_setstacksize failed");
154 for (i
= 0; i
< N
; ++i
)
155 if (pthread_create (&th
[i
], &a
, tf
, cbs
[i
]) != 0)
157 puts ("pthread_create failed");
161 if (pthread_attr_destroy (&a
) != 0)
163 puts ("attr_destroy failed");
167 pthread_barrier_wait (&b
);
171 sigaddset (&ss
, THE_SIG
);
172 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
174 puts ("pthread_sigmask failed");
178 /* Start sending signals. */
179 for (i
= 0; i
< TOTAL_SIGS
; ++i
)
181 if (kill (getpid (), THE_SIG
) != 0)
183 puts ("kill failed");
187 if (TEMP_FAILURE_RETRY (sem_wait (&s
)) != 0)
189 puts ("sem_wait failed");
196 pthread_barrier_wait (&b
);
198 for (i
= 0; i
< N
; ++i
)
199 if (pthread_join (th
[i
], NULL
) != 0)
201 puts ("join failed");