From e0e33b5bf73fd64ac8d88c64368ee3eb8dcfb937 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Tue, 12 Nov 2024 14:31:35 +0100 Subject: [PATCH] use gettid on Linux after all, via syscall() --- src/runtime/process.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/process.cpp b/src/runtime/process.cpp index 9bcc2f9c7268..32493d6aba2c 100644 --- a/src/runtime/process.cpp +++ b/src/runtime/process.cpp @@ -27,6 +27,10 @@ Author: Jared Roesch #include // NOLINT #endif +#ifdef __linux +#include +#endif + #include "runtime/object.h" #include "runtime/io.h" #include "runtime/array_ref.h" @@ -323,8 +327,9 @@ extern "C" LEAN_EXPORT obj_res lean_io_get_thread_id(obj_arg) { #elif defined(__APPLE__) pthread_threadid_np(NULL, &tid); #else - // should use gettid, but that is glibc 2.30+ - tid = static_cast(pthread_self()); + // since Linux 2.4.11, our glibc 2.27 requires at least 3.2 + // glibc 2.30 would provide a wrapper + tid = (pid_t)syscall(SYS_gettid); #endif return lean_io_result_mk_ok(box_uint64(tid)); }