1 /* Copyright (C) 2003 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/>. */
28 static pthread_barrier_t bar
;
40 pthread_t self
= pthread_self ();
43 for (i
= 0; i
< N
; ++i
)
46 if ((uintptr_t) ti
[i
].p
<= (uintptr_t) &self
47 && (uintptr_t) ti
[i
].p
+ 2 * MINSIGSTKSZ
> (uintptr_t) &self
)
49 puts ("alt stack not used");
53 printf ("thread %zu used alt stack for signal %d\n", i
, sig
);
58 puts ("handler: thread not found");
66 size_t nr
= (uintptr_t) arg
;
69 puts ("wrong nr parameter");
76 for (i
= 0; i
< N
; ++i
)
78 if (sigaddset (&ss
, sig1
+ i
) != 0)
80 puts ("tf: sigaddset failed");
83 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
85 puts ("tf: sigmask failed");
89 void *p
= malloc (2 * MINSIGSTKSZ
);
92 puts ("tf: malloc failed");
98 s
.ss_size
= 2 * MINSIGSTKSZ
;
100 if (sigaltstack (&s
, NULL
) != 0)
102 puts ("tf: sigaltstack failed");
107 ti
[nr
].s
= pthread_self ();
109 pthread_barrier_wait (&bar
);
111 pthread_barrier_wait (&bar
);
121 if (sig1
+ N
> SIGRTMAX
)
123 puts ("too few RT signals");
128 sa
.sa_handler
= handler
;
130 sigemptyset (&sa
.sa_mask
);
132 if (sigaction (sig1
, &sa
, NULL
) != 0
133 || sigaction (sig1
+ 1, &sa
, NULL
) != 0
134 || sigaction (sig1
+ 2, &sa
, NULL
) != 0)
136 puts ("sigaction failed");
140 if (pthread_barrier_init (&bar
, NULL
, 1 + N
) != 0)
142 puts ("barrier_init failed");
148 for (i
= 0; i
< N
; ++i
)
149 if (pthread_create (&th
[i
], NULL
, tf
, (void *) (long int) i
) != 0)
151 puts ("create failed");
155 /* Block the three signals. */
158 for (i
= 0; i
<= N
; ++i
)
159 sigaddset (&ss
, sig1
+ i
);
160 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
162 puts ("main: sigmask failed");
166 pthread_barrier_wait (&bar
);
168 /* Send some signals. */
169 pid_t me
= getpid ();
171 for (i
= 0; i
< N
; ++i
)
175 /* Give the signals a chance to be worked on. */
178 pthread_barrier_wait (&bar
);
180 for (i
= 0; i
< N
; ++i
)
181 if (pthread_join (th
[i
], NULL
) != 0)
183 puts ("join failed");
190 #define TEST_FUNCTION do_test ()
191 #include "../test-skeleton.c"