1 /* Bug 14333: Support file for atexit/exit, etc. race tests.
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* This file must be run from within a directory called "stdlib". */
21 /* The atexit/exit, at_quick_exit/quick_exit, __cxa_atexit/exit, etc.
22 exhibited data race while accessing destructor function list (Bug 14333).
24 This test spawns large number of threads, which all race to register
25 large number of destructors.
27 Before the fix, running this test resulted in a SIGSEGV.
28 After the fix, we expect clean process termination. */
30 #if !defined(CALL_EXIT) || !defined(CALL_ATEXIT)
31 #error Must define CALL_EXIT and CALL_ATEXIT before using this file.
36 #include <support/xthread.h>
39 const size_t kNumThreads
= 1024;
40 const size_t kNumHandlers
= 1024;
41 const size_t kStacksize
=
42 #ifdef PTHREAD_STACK_MIN
43 0x20000 < PTHREAD_STACK_MIN
? PTHREAD_STACK_MIN
:
48 threadfunc (void *unused
)
51 for (i
= 0; i
< kNumHandlers
; ++i
) {
63 xpthread_attr_init (&attr
);
64 xpthread_attr_setdetachstate (&attr
, 1);
66 /* With default 8MiB Linux stack size, creating 1024 threads can cause
67 VM exhausiton on 32-bit machines. Reduce stack size of each thread to
68 128KiB for a maximum required VM size of 128MiB. */
69 xpthread_attr_setstacksize (&attr
, kStacksize
);
71 for (i
= 0; i
< kNumThreads
; ++i
) {
72 xpthread_create (&attr
, threadfunc
, NULL
);
74 xpthread_attr_destroy (&attr
);
79 #define TEST_FUNCTION do_test
80 #include <support/test-driver.c>