Fix p_secstodate overflow handling (bug 22463).
[glibc.git] / stdlib / test-atexit-race-common.c
blob3a03e06cb97e374d2c56410ffa5fb34e4fcae1f5
1 /* Bug 14333: Support file for atexit/exit, etc. race tests.
2 Copyright (C) 2017 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 <http://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>
38 const size_t kNumThreads = 1024;
39 const size_t kNumHandlers = 1024;
41 static void *
42 threadfunc (void *unused)
44 size_t i;
45 for (i = 0; i < kNumHandlers; ++i) {
46 CALL_ATEXIT;
48 return NULL;
51 static int
52 do_test (void)
54 size_t i;
55 pthread_attr_t attr;
57 xpthread_attr_init (&attr);
58 xpthread_attr_setdetachstate (&attr, 1);
60 /* With default 8MiB Linux stack size, creating 1024 threads can cause
61 VM exhausiton on 32-bit machines. Reduce stack size of each thread to
62 128KiB for a maximum required VM size of 128MiB. */
63 xpthread_attr_setstacksize (&attr, 128 * 1024);
65 for (i = 0; i < kNumThreads; ++i) {
66 xpthread_create (&attr, threadfunc, NULL);
68 xpthread_attr_destroy (&attr);
70 CALL_EXIT;
73 #define TEST_FUNCTION do_test
74 #include <support/test-driver.c>