[libcxx-commits] [libcxx] [libc++][AIX] Fix force_thread_creation_failure by using RLIMIT_THREADS (PR #188787)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 30 21:39:20 PDT 2026


https://github.com/Himadhith updated https://github.com/llvm/llvm-project/pull/188787

>From 96f65e83ac6b27a1ec6ba77876ddb67a2ef57a6a Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Thu, 26 Mar 2026 14:01:12 -0400
Subject: [PATCH 1/5] [libc++][AIX] Fix force_thread_creation_failure by using
 RLIMIT_THREADS

---
 .../futures/futures.async/thread_create_failure.pass.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
index 70009589e985b..ebc121984d061 100644
--- a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -17,7 +17,7 @@
 // UNSUPPORTED: windows
 
 // AIX, macOS and FreeBSD seem to limit the number of processes, not threads via RLIMIT_NPROC
-// XFAIL: target={{.+}}-aix{{.*}}
+// But there is RLIMIT_THREADS in AIX which can be used here to limit the threads.
 // XFAIL: target={{.+}}-apple-{{.*}}
 // XFAIL: freebsd
 
@@ -33,7 +33,12 @@
 
 #if __has_include(<sys/resource.h>)
 #  include <sys/resource.h>
-#  ifdef RLIMIT_NPROC
+#  if defined(_AIX) && defined(RLIMIT_THREADS)
+void force_thread_creation_failure() {
+  rlimit lim = {1, 1};
+  assert(setrlimit(RLIMIT_THREADS, &lim) == 0);
+}
+#  elif RLIMIT_NPROC
 void force_thread_creation_failure() {
   rlimit lim = {1, 1};
   assert(setrlimit(RLIMIT_NPROC, &lim) == 0);

>From 19e6b7b822651b3e794428e009fb7de24885b53b Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Thu, 26 Mar 2026 14:39:02 -0400
Subject: [PATCH 2/5] Adding defined to RLIMIT_NPROC

---
 .../thread/futures/futures.async/thread_create_failure.pass.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
index ebc121984d061..91b15e9361c20 100644
--- a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -38,7 +38,7 @@ void force_thread_creation_failure() {
   rlimit lim = {1, 1};
   assert(setrlimit(RLIMIT_THREADS, &lim) == 0);
 }
-#  elif RLIMIT_NPROC
+#  elif defined(RLIMIT_NPROC)
 void force_thread_creation_failure() {
   rlimit lim = {1, 1};
   assert(setrlimit(RLIMIT_NPROC, &lim) == 0);

>From 510f5111d67ab7c6663c95aa7cbeb1233cb531f1 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Fri, 27 Mar 2026 03:39:28 -0400
Subject: [PATCH 3/5] Refactoring code

---
 .../futures/futures.async/thread_create_failure.pass.cpp  | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
index 91b15e9361c20..95db606233dc4 100644
--- a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -33,22 +33,20 @@
 
 #if __has_include(<sys/resource.h>)
 #  include <sys/resource.h>
-#  if defined(_AIX) && defined(RLIMIT_THREADS)
+
 void force_thread_creation_failure() {
   rlimit lim = {1, 1};
+#  if defined(_AIX) && defined(RLIMIT_THREADS)
   assert(setrlimit(RLIMIT_THREADS, &lim) == 0);
-}
 #  elif defined(RLIMIT_NPROC)
-void force_thread_creation_failure() {
-  rlimit lim = {1, 1};
   assert(setrlimit(RLIMIT_NPROC, &lim) == 0);
-}
 #  else
 #    error "No known way to force only one thread being available"
 #  endif
 #else
 #  error "No known way to force only one thread being available"
 #endif
+}
 
 int main(int, char**) {
   force_thread_creation_failure();

>From 02285fab979802576b43c8a4a05ac1f2224a27d1 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Fri, 27 Mar 2026 03:46:06 -0400
Subject: [PATCH 4/5] Review changes

---
 .../futures.async/thread_create_failure.pass.cpp  | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
index 95db606233dc4..87b7b556db5aa 100644
--- a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -16,8 +16,8 @@
 // There is no way to limit the number of threads on windows
 // UNSUPPORTED: windows
 
-// AIX, macOS and FreeBSD seem to limit the number of processes, not threads via RLIMIT_NPROC
-// But there is RLIMIT_THREADS in AIX which can be used here to limit the threads.
+// AIX, macOS and FreeBSD seem to limit the number of processes, not threads via RLIMIT_NPROC.
+// IN AIX RLIMIT_THREADS can be used to limit the threads.
 // XFAIL: target={{.+}}-apple-{{.*}}
 // XFAIL: freebsd
 
@@ -33,19 +33,20 @@
 
 #if __has_include(<sys/resource.h>)
 #  include <sys/resource.h>
-
-void force_thread_creation_failure() {
-  rlimit lim = {1, 1};
+// Using the macro TEST_RLIMIT to determine the type of RLIMIT based on the platform.
 #  if defined(_AIX) && defined(RLIMIT_THREADS)
-  assert(setrlimit(RLIMIT_THREADS, &lim) == 0);
+#    define TEST_RLIMIT RLIMIT_THREADS
 #  elif defined(RLIMIT_NPROC)
-  assert(setrlimit(RLIMIT_NPROC, &lim) == 0);
+#    define TEST_RLIMIT RLIMIT_NPROC
 #  else
 #    error "No known way to force only one thread being available"
 #  endif
 #else
 #  error "No known way to force only one thread being available"
 #endif
+void force_thread_creation_failure() {
+  rlimit lim = {1, 1};
+  assert(setrlimit(TEST_RLIMIT, &lim) == 0);
 }
 
 int main(int, char**) {

>From e9ba99ca4ee42e1a376812be540fe4ef83787fb2 Mon Sep 17 00:00:00 2001
From: himadhith <himadhith.v at ibm.com>
Date: Fri, 27 Mar 2026 14:02:44 -0400
Subject: [PATCH 5/5] Comment changes

---
 .../futures/futures.async/thread_create_failure.pass.cpp       | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
index 87b7b556db5aa..76e12d51751d9 100644
--- a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -16,8 +16,7 @@
 // There is no way to limit the number of threads on windows
 // UNSUPPORTED: windows
 
-// AIX, macOS and FreeBSD seem to limit the number of processes, not threads via RLIMIT_NPROC.
-// IN AIX RLIMIT_THREADS can be used to limit the threads.
+// macOS and FreeBSD seem to limit the number of processes, not threads via RLIMIT_NPROC.
 // XFAIL: target={{.+}}-apple-{{.*}}
 // XFAIL: freebsd
 



More information about the libcxx-commits mailing list