1 /* Test that raise sends signal to current thread even if blocked.
2 Copyright (C) 2021-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
20 #include <support/check.h>
21 #include <support/xsignal.h>
22 #include <support/xthread.h>
26 /* Used to create a dummy thread ID distinct from all other thread
34 static volatile pthread_t signal_thread
;
37 signal_handler (int signo
)
39 signal_thread
= pthread_self ();
42 /* Used to ensure that waiting_thread has launched and can accept
44 static pthread_barrier_t barrier
;
47 waiting_thread (void *ignored
)
49 xpthread_barrier_wait (&barrier
);
57 xsignal (SIGUSR1
, signal_handler
);
58 xpthread_barrier_init (&barrier
, NULL
, 2);
60 /* Distinct thread ID value to */
61 pthread_t dummy
= xpthread_create (NULL
, noop
, NULL
);
62 signal_thread
= dummy
;
64 pthread_t helper
= xpthread_create (NULL
, waiting_thread
, NULL
);
66 /* Make sure that the thread is running. */
67 xpthread_barrier_wait (&barrier
);
69 /* Block signals on this thread. */
72 xpthread_sigmask (SIG_BLOCK
, &set
, NULL
);
74 /* Send the signal to this thread. It must not be delivered. */
76 TEST_VERIFY (signal_thread
== dummy
);
78 /* Wait a bit to give a chance for signal delivery (increases
79 chances of failure with bug 28407). */
82 /* Unblocking should cause synchronous delivery of the signal. */
83 xpthread_sigmask (SIG_UNBLOCK
, &set
, NULL
);
84 TEST_VERIFY (signal_thread
== pthread_self ());
86 xpthread_cancel (helper
);
87 xpthread_join (helper
);
88 xpthread_join (dummy
);
92 #include <support/test-driver.c>