This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Tweak test-*exit-race tests to honor the maximum number of processes
- From: "Dmitry V. Levin" <ldv at altlinux dot org>
- To: libc-alpha at sourceware dot org
- Date: Tue, 30 Jan 2018 19:54:53 +0300
- Subject: [PATCH] Tweak test-*exit-race tests to honor the maximum number of processes
- Authentication-results: sourceware.org; auth=none
When the number of threads created by test-*exit-race tests is close
to the maximum number of simultaneous processes per uid, these tests
fail with the following diagnostics:
error: xpthread_check_return.c:32: pthread_create: Resource temporarily unavailable
Workaround this issue by limiting the number of threads created
by these tests to sysconf (_SC_CHILD_MAX) / 2.
Tested that these tests still fail reliably on x86_64 with glibc-2.26
and sysconf (_SC_CHILD_MAX) == 512.
* stdlib/test-atexit-race-common.c: Include <unistd.h>.
(kNumThreads): Remove const qualifier.
(do_test): Limit kNumThreads to sysconf (_SC_CHILD_MAX) / 2.
---
ChangeLog | 6 ++++++
stdlib/test-atexit-race-common.c | 10 ++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/stdlib/test-atexit-race-common.c b/stdlib/test-atexit-race-common.c
index 4d7f911..7a65264 100644
--- a/stdlib/test-atexit-race-common.c
+++ b/stdlib/test-atexit-race-common.c
@@ -33,10 +33,11 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <support/xthread.h>
-const size_t kNumThreads = 1024;
-const size_t kNumHandlers = 1024;
+static size_t kNumThreads = 1024;
+static const size_t kNumHandlers = 1024;
static void *
threadfunc (void *unused)
@@ -62,6 +63,11 @@ do_test (void)
128KiB for a maximum required VM size of 128MiB. */
xpthread_attr_setstacksize (&attr, 128 * 1024);
+ long nproc = sysconf (_SC_CHILD_MAX);
+
+ if (nproc > 0 && nproc / 2 < kNumThreads)
+ kNumThreads = nproc / 2;
+
for (i = 0; i < kNumThreads; ++i) {
xpthread_create (&attr, threadfunc, NULL);
}
--
ldv