[llvm] Enable using threads on z/OS (PR #171847)
Sean Perry via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 8 11:11:47 PST 2026
https://github.com/perry-ca updated https://github.com/llvm/llvm-project/pull/171847
>From fdd65dddc3a378665933437e09298112e6c1d393 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Wed, 3 Dec 2025 10:57:25 -0500
Subject: [PATCH 1/6] use correct type for thread id
---
llvm/include/llvm/Support/thread.h | 14 ++++++++++++--
llvm/lib/Support/Unix/Threading.inc | 12 ++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Support/thread.h b/llvm/include/llvm/Support/thread.h
index 51873e7d529bf..aad82e485ab57 100644
--- a/llvm/include/llvm/Support/thread.h
+++ b/llvm/include/llvm/Support/thread.h
@@ -51,7 +51,11 @@ class thread {
public:
#ifdef LLVM_ON_UNIX
using native_handle_type = pthread_t;
+#ifdef __MVS__
+ using id = unsigned long long;
+#else
using id = pthread_t;
+#endif
using start_routine_type = void *(*)(void *);
template <typename CalleeTuple> static void *ThreadProxy(void *Ptr) {
@@ -97,7 +101,13 @@ class thread {
return *this;
}
- bool joinable() const noexcept { return Thread != native_handle_type(); }
+ bool is_null() const noexcept {
+ return get_id() == 0;
+ }
+
+ bool joinable() const noexcept {
+ return !is_null();
+ }
inline id get_id() const noexcept;
@@ -133,7 +143,7 @@ thread::thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
Thread = llvm_execute_on_thread_impl(ThreadProxy<CalleeTuple>, Callee.get(),
StackSizeInBytes);
- if (Thread != native_handle_type())
+ if (!is_null())
Callee.release();
}
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index f016ed6937524..cceffcb34c547 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -119,9 +119,17 @@ void llvm_thread_join_impl(pthread_t Thread) {
}
}
-pthread_t llvm_thread_get_id_impl(pthread_t Thread) { return Thread; }
+llvm::thread::id llvm_thread_get_id_impl(pthread_t Thread) {
+#ifdef __MVS__
+ return Thread.__;
+#else
+ return Thread;
+#endif
+}
-pthread_t llvm_thread_get_current_id_impl() { return ::pthread_self(); }
+llvm::thread::id llvm_thread_get_current_id_impl() {
+ return llvm_thread_get_id_impl(::pthread_self());
+}
} // namespace llvm
>From 82de84df3c2640fab99742cbb37edaa43078b22f Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Wed, 3 Dec 2025 21:06:35 +0000
Subject: [PATCH 2/6] Remove unused variable blocking z/OS build & one more
place that retrieves thread id
---
llvm/lib/Support/Parallel.cpp | 2 --
llvm/lib/Support/Unix/Threading.inc | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp
index ab220b8f2ceba..97c16b0eb333a 100644
--- a/llvm/lib/Support/Parallel.cpp
+++ b/llvm/lib/Support/Parallel.cpp
@@ -129,8 +129,6 @@ class ThreadPoolExecutor : public Executor {
// first successful tryAcquire() in a process. This guarantees forward
// progress without requiring a dedicated "always-on" thread here.
- static thread_local std::unique_ptr<ExponentialBackoff> Backoff;
-
while (true) {
if (TheJobserver) {
// Jobserver-mode scheduling:
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index cceffcb34c547..2865ef3b17efa 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -156,6 +156,8 @@ uint64_t llvm::get_threadid() {
return uint64_t(syscall(__NR_gettid));
#elif defined(_AIX)
return uint64_t(thread_self());
+#elif defined(__MVS__)
+ return llvm_thread_get_id_impl(pthread_self());
#else
return uint64_t(pthread_self());
#endif
>From 6c69a623bfc84b16f6f6cd8f417458ea48096a38 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Thu, 11 Dec 2025 10:12:40 -0500
Subject: [PATCH 3/6] enable using threads on z/OS
---
llvm/CMakeLists.txt | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 908580f791f36..58c3c598c49b4 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -609,12 +609,7 @@ option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
-# On z/OS, threads cannot be used because TLS is not supported.
-if (CMAKE_SYSTEM_NAME MATCHES "OS390")
- option(LLVM_ENABLE_THREADS "Use threads if available." OFF)
-else()
- option(LLVM_ENABLE_THREADS "Use threads if available." ON)
-endif()
+option(LLVM_ENABLE_THREADS "Use threads if available." ON)
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
>From b76be55ee310ede8d20826c877b98fde821937f1 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Thu, 11 Dec 2025 16:31:44 -0500
Subject: [PATCH 4/6] reformat
---
llvm/include/llvm/Support/thread.h | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Support/thread.h b/llvm/include/llvm/Support/thread.h
index aad82e485ab57..5ae76e98da949 100644
--- a/llvm/include/llvm/Support/thread.h
+++ b/llvm/include/llvm/Support/thread.h
@@ -101,13 +101,9 @@ class thread {
return *this;
}
- bool is_null() const noexcept {
- return get_id() == 0;
- }
+ bool is_null() const noexcept { return get_id() == 0; }
- bool joinable() const noexcept {
- return !is_null();
- }
+ bool joinable() const noexcept { return !is_null(); }
inline id get_id() const noexcept;
>From 00f0b28e4cbee90ba2102bd4ac8ea1e2babacf42 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Thu, 8 Jan 2026 10:20:08 -0500
Subject: [PATCH 5/6] use pthread_equal & remove is_null
---
llvm/include/llvm/Support/thread.h | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Support/thread.h b/llvm/include/llvm/Support/thread.h
index 5ae76e98da949..1b9aecf8c5f30 100644
--- a/llvm/include/llvm/Support/thread.h
+++ b/llvm/include/llvm/Support/thread.h
@@ -101,9 +101,7 @@ class thread {
return *this;
}
- bool is_null() const noexcept { return get_id() == 0; }
-
- bool joinable() const noexcept { return !is_null(); }
+ bool joinable() const noexcept { return !pthread_equal(Thread, native_handle_type()); }
inline id get_id() const noexcept;
@@ -139,7 +137,7 @@ thread::thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
Thread = llvm_execute_on_thread_impl(ThreadProxy<CalleeTuple>, Callee.get(),
StackSizeInBytes);
- if (!is_null())
+ if (joinable())
Callee.release();
}
>From c98724b2c55b45ec755f3d8b043385ac26d3425a Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Thu, 8 Jan 2026 14:11:24 -0500
Subject: [PATCH 6/6] pthread_equal not available on windows
---
llvm/include/llvm/Support/thread.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/thread.h b/llvm/include/llvm/Support/thread.h
index 1b9aecf8c5f30..e25c84415327a 100644
--- a/llvm/include/llvm/Support/thread.h
+++ b/llvm/include/llvm/Support/thread.h
@@ -101,7 +101,7 @@ class thread {
return *this;
}
- bool joinable() const noexcept { return !pthread_equal(Thread, native_handle_type()); }
+ bool joinable() const noexcept { return get_id() != 0; }
inline id get_id() const noexcept;
More information about the llvm-commits
mailing list