math: Remove bogus math implementations
[glibc.git] / stdlib / test-atexit-race-common.c
blob0ef539c6b5735ca221ca2266e5aef571909a8425
1 /* Bug 14333: Support file for atexit/exit, etc. race tests.
2 Copyright (C) 2017-2024 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.
32 #endif
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <support/xthread.h>
37 #include <limits.h>
39 const size_t kNumThreads = 1024;
40 const size_t kNumHandlers = 1024;
42 static void *
43 threadfunc (void *unused)
45 size_t i;
46 for (i = 0; i < kNumHandlers; ++i) {
47 CALL_ATEXIT;
49 return NULL;
52 static int
53 do_test (void)
55 size_t i;
56 pthread_attr_t attr;
58 xpthread_attr_init (&attr);
59 xpthread_attr_setdetachstate (&attr, 1);
61 /* With default 8MiB Linux stack size, creating 1024 threads can cause
62 VM exhausiton on 32-bit machines. Reduce stack size of each thread to
63 128KiB for a maximum required VM size of 128MiB. */
64 size_t kStacksize =
65 #ifdef PTHREAD_STACK_MIN
66 0x20000 < PTHREAD_STACK_MIN ? PTHREAD_STACK_MIN :
67 #endif
68 0x20000;
70 xpthread_attr_setstacksize (&attr, kStacksize);
72 for (i = 0; i < kNumThreads; ++i) {
73 xpthread_create (&attr, threadfunc, NULL);
75 xpthread_attr_destroy (&attr);
77 CALL_EXIT;
80 #define TEST_FUNCTION do_test
81 #include <support/test-driver.c>