1 /* Copyright (C) 2003-2016 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/>. */
30 static pthread_barrier_t bar
;
42 pthread_t self
= pthread_self ();
45 for (i
= 0; i
< N
; ++i
)
48 if ((uintptr_t) ti
[i
].p
<= (uintptr_t) &self
49 && (uintptr_t) ti
[i
].p
+ 2 * MINSIGSTKSZ
> (uintptr_t) &self
)
51 puts ("alt stack not used");
55 printf ("thread %zu used alt stack for signal %d\n", i
, sig
);
60 puts ("handler: thread not found");
68 size_t nr
= (uintptr_t) arg
;
71 puts ("wrong nr parameter");
78 for (i
= 0; i
< N
; ++i
)
80 if (sigaddset (&ss
, sig1
+ i
) != 0)
82 puts ("tf: sigaddset failed");
85 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
87 puts ("tf: sigmask failed");
91 void *p
= malloc (2 * MINSIGSTKSZ
);
94 puts ("tf: malloc failed");
100 s
.ss_size
= 2 * MINSIGSTKSZ
;
102 if (sigaltstack (&s
, NULL
) != 0)
104 puts ("tf: sigaltstack failed");
109 ti
[nr
].s
= pthread_self ();
111 pthread_barrier_wait (&bar
);
113 pthread_barrier_wait (&bar
);
123 if (sig1
+ N
> SIGRTMAX
)
125 puts ("too few RT signals");
130 sa
.sa_handler
= handler
;
132 sigemptyset (&sa
.sa_mask
);
134 if (sigaction (sig1
, &sa
, NULL
) != 0
135 || sigaction (sig1
+ 1, &sa
, NULL
) != 0
136 || sigaction (sig1
+ 2, &sa
, NULL
) != 0)
138 puts ("sigaction failed");
142 if (pthread_barrier_init (&bar
, NULL
, 1 + N
) != 0)
144 puts ("barrier_init failed");
150 for (i
= 0; i
< N
; ++i
)
151 if (pthread_create (&th
[i
], NULL
, tf
, (void *) (long int) i
) != 0)
153 puts ("create failed");
157 /* Block the three signals. */
160 for (i
= 0; i
<= N
; ++i
)
161 sigaddset (&ss
, sig1
+ i
);
162 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
164 puts ("main: sigmask failed");
168 pthread_barrier_wait (&bar
);
170 /* Send some signals. */
171 pid_t me
= getpid ();
173 for (i
= 0; i
< N
; ++i
)
177 /* Give the signals a chance to be worked on. */
180 pthread_barrier_wait (&bar
);
182 for (i
= 0; i
< N
; ++i
)
183 if (pthread_join (th
[i
], NULL
) != 0)
185 puts ("join failed");
192 # define TEST_FUNCTION do_test ()
195 # define TEST_FUNCTION 0
197 #include "../test-skeleton.c"