1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2014-2022 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Used to individually advance each thread to the desired stopping point. */
26 sig_atomic_t sigusr1_received;
27 sig_atomic_t sigusr2_received;
28 sig_atomic_t sigabrt_received;
30 /* Number of threads currently running. */
32 pthread_mutex_t thread_count_mutex;
33 pthread_cond_t thread_count_condvar;
36 incr_thread_count (void)
38 pthread_mutex_lock (&thread_count_mutex);
40 pthread_cond_signal (&thread_count_condvar);
41 pthread_mutex_unlock (&thread_count_mutex);
45 sigusr1_handler (int sig)
51 sigusr2_handler (int sig)
57 sigabrt_handler (int sig)
63 sigusr1_thread_function (void *unused)
68 pthread_kill (pthread_self (), SIGUSR1);
72 sigusr2_thread_function (void *unused)
77 /* pthread_kill (pthread_self (), SIGUSR2); - manually injected by gdb */
80 /* Wait until all threads are at a point where a backtrace will
81 show the thread entry point function. */
84 wait_all_threads_running (int nr_threads)
86 pthread_mutex_lock (&thread_count_mutex);
90 if (thread_count == nr_threads)
92 pthread_mutex_unlock (&thread_count_mutex);
95 pthread_cond_wait (&thread_count_condvar, &thread_count_mutex);
100 all_threads_running (void)
107 all_threads_done (void)
114 pthread_t sigusr1_thread, sigusr2_thread;
116 /* Protect against running forever. */
119 signal (SIGUSR1, sigusr1_handler);
120 signal (SIGUSR2, sigusr2_handler);
121 signal (SIGABRT, sigabrt_handler);
123 /* Don't let any thread advance past initialization. */
126 pthread_mutex_init (&thread_count_mutex, NULL);
127 pthread_cond_init (&thread_count_condvar, NULL);
130 pthread_create (&sigusr1_thread, NULL, sigusr1_thread_function, NULL);
131 pthread_create (&sigusr2_thread, NULL, sigusr2_thread_function, NULL);
132 wait_all_threads_running (NR_THREADS);
133 all_threads_running ();
135 pthread_kill (pthread_self (), SIGABRT);
137 pthread_join (sigusr1_thread, NULL);
138 pthread_join (sigusr2_thread, NULL);