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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 static pthread_barrier_t bar
;
41 pthread_t self
= pthread_self ();
44 for (i
= 0; i
< N
; ++i
)
47 if ((uintptr_t) ti
[i
].p
<= (uintptr_t) &self
48 && (uintptr_t) ti
[i
].p
+ 2 * MINSIGSTKSZ
> (uintptr_t) &self
)
50 puts ("alt stack not used");
54 printf ("thread %zu used alt stack for signal %d\n", i
, sig
);
59 puts ("handler: thread not found");
67 size_t nr
= (uintptr_t) arg
;
70 puts ("wrong nr parameter");
77 for (i
= 0; i
< N
; ++i
)
79 if (sigaddset (&ss
, sig1
+ i
) != 0)
81 puts ("tf: sigaddset failed");
84 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
86 puts ("tf: sigmask failed");
90 void *p
= malloc (2 * MINSIGSTKSZ
);
93 puts ("tf: malloc failed");
99 s
.ss_size
= 2 * MINSIGSTKSZ
;
101 if (sigaltstack (&s
, NULL
) != 0)
103 puts ("tf: sigaltstack failed");
108 ti
[nr
].s
= pthread_self ();
110 pthread_barrier_wait (&bar
);
112 pthread_barrier_wait (&bar
);
122 if (sig1
+ N
> SIGRTMAX
)
124 puts ("too few RT signals");
129 sa
.sa_handler
= handler
;
131 sigemptyset (&sa
.sa_mask
);
133 if (sigaction (sig1
, &sa
, NULL
) != 0
134 || sigaction (sig1
+ 1, &sa
, NULL
) != 0
135 || sigaction (sig1
+ 2, &sa
, NULL
) != 0)
137 puts ("sigaction failed");
141 if (pthread_barrier_init (&bar
, NULL
, 1 + N
) != 0)
143 puts ("barrier_init failed");
149 for (i
= 0; i
< N
; ++i
)
150 if (pthread_create (&th
[i
], NULL
, tf
, (void *) (long int) i
) != 0)
152 puts ("create failed");
156 /* Block the three signals. */
159 for (i
= 0; i
<= N
; ++i
)
160 sigaddset (&ss
, sig1
+ i
);
161 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
163 puts ("main: sigmask failed");
167 pthread_barrier_wait (&bar
);
169 /* Send some signals. */
170 pid_t me
= getpid ();
172 for (i
= 0; i
< N
; ++i
)
176 /* Give the signals a chance to be worked on. */
179 pthread_barrier_wait (&bar
);
181 for (i
= 0; i
< N
; ++i
)
182 if (pthread_join (th
[i
], NULL
) != 0)
184 puts ("join failed");
191 #define TEST_FUNCTION do_test ()
192 #include "../test-skeleton.c"