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/>. */
20 #include <sys/syscall.h>
22 #define NUM_THREADS 32
24 pthread_barrier_t barrier
;
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
37 syscall (SYS_exit
, exitcode
);
43 int thread_return_value
= *(int *) arg
;
45 do_exit (thread_return_value
);
51 pthread_t threads
[NUM_THREADS
];
52 int thread_return_val
[NUM_THREADS
];
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
]);