Debian Codegraph @

gdb/testsuite/gdb.threads/process-exit-status-is-leader-exit-status.c

raw symbols SCIP
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2022-2024 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>. */
17
18 #include <pthread.h>
19 #include <unistd.h>
20 #include <sys/syscall.h>
21
22 #define NUM_THREADS 32
23
24 pthread_barrier_t barrier;
25
26 static void
27 do_exit (int exitcode)
28 {
29 /* Synchronize all threads up to here so that they all exit at
30 roughly the same time. */
31 pthread_barrier_wait (&barrier);
32
33 /* All threads exit with SYS_exit, even the main thread, to avoid
34 exiting with a group-exit syscall, as that syscall changes the
35 exit status of all still-alive threads, thus potentially masking
36 a bug. */
37 syscall (SYS_exit, exitcode);
38 }
39
40 static void *
41 start (void *arg)
42 {
43 int thread_return_value = *(int *) arg;
44
45 do_exit (thread_return_value);
46 return NULL;
47 }
48
49 int
50 main(void)
51 {
52 pthread_t threads[NUM_THREADS];
53 int thread_return_val[NUM_THREADS];
54 int i;
55
56 pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1);
57
58 for (i = 0; i < NUM_THREADS; ++i)
59 {
60 thread_return_val[i] = i + 2;
61 pthread_create (&threads[i], NULL, start, &thread_return_val[i]);
62 }
63
64 do_exit (1);
65 }