1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2021-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/>. */
28 #define NUM_FORKING_THREADS 12
30 static pthread_barrier_t barrier;
31 static volatile int should_exit = 0;
34 sigusr1_handler (int sig, siginfo_t *siginfo, void *context)
40 forking_thread (void *arg)
42 /* Wait for all forking threads to have spawned before fork-spamming. */
43 pthread_barrier_wait (&barrier);
57 int ret = waitpid (pid, &status, 0);
59 assert (WIFEXITED (status));
60 assert (WEXITSTATUS (status) == 8);
68 break_here_first (void)
77 pthread_t forking_threads[NUM_FORKING_THREADS];
82 /* Just to make sure we don't run for ever. */
89 pthread_barrier_init (&barrier, NULL, NUM_FORKING_THREADS);
91 memset (&sa, 0, sizeof (sa));
92 sa.sa_sigaction = sigusr1_handler;
93 ret = sigaction (SIGUSR1, &sa, NULL);
96 for (i = 0; i < NUM_FORKING_THREADS; ++i)
98 ret = pthread_create (&forking_threads[i], NULL, forking_thread, NULL);
102 for (i = 0; i < NUM_FORKING_THREADS; ++i)
104 ret = pthread_join (forking_threads[i], NULL);
108 FILE *f = fopen (TOUCH_FILE_PATH, "w");