]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdlib/test-atexit-race-common.c
stdlib: Fix tst-rand48.c printf types
[thirdparty/glibc.git] / stdlib / test-atexit-race-common.c
index b3792837c71ae295baf524d3606f0eb5160ca4b9..2770a33fe8a3b3fe7c90a75af1700e5251ccb87b 100644 (file)
@@ -1,5 +1,5 @@
 /* Bug 14333: Support file for atexit/exit, etc. race tests.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   Copyright (C) 2017-2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 /* This file must be run from within a directory called "stdlib".  */
 
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <support/xthread.h>
+#include <limits.h>
 
 const size_t kNumThreads = 1024;
 const size_t kNumHandlers = 1024;
@@ -57,6 +58,17 @@ do_test (void)
   xpthread_attr_init (&attr);
   xpthread_attr_setdetachstate (&attr, 1);
 
+  /* With default 8MiB Linux stack size, creating 1024 threads can cause
+     VM exhausiton on 32-bit machines.  Reduce stack size of each thread to
+     128KiB for a maximum required VM size of 128MiB.  */
+  size_t kStacksize =
+#ifdef PTHREAD_STACK_MIN
+    0x20000 < PTHREAD_STACK_MIN ? PTHREAD_STACK_MIN :
+#endif
+    0x20000;
+
+  xpthread_attr_setstacksize (&attr, kStacksize);
+
   for (i = 0; i < kNumThreads; ++i) {
     xpthread_create (&attr, threadfunc, NULL);
   }