Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.threads / process-exit-status-is-leader-exit-status.c
blobc27c266ef28fe6a49f0ab822a13131d1e06fa460
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 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/>. */
18 #include <pthread.h>
19 #include <unistd.h>
20 #include <sys/syscall.h>
22 #define NUM_THREADS 32
24 pthread_barrier_t barrier;
26 static void
27 do_exit (int exitcode)
29 /* Synchronize all threads up to here so that they all exit at
30 roughly the same time. */
31 pthread_barrier_wait (&barrier);
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);
40 static void *
41 start (void *arg)
43 int thread_return_value = *(int *) arg;
45 do_exit (thread_return_value);
48 int
49 main(void)
51 pthread_t threads[NUM_THREADS];
52 int thread_return_val[NUM_THREADS];
53 int i;
55 pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1);
57 for (i = 0; i < NUM_THREADS; ++i)
59 thread_return_val[i] = i + 2;
60 pthread_create (&threads[i], NULL, start, &thread_return_val[i]);
63 do_exit (1);