From 3f4ccab49542ac19df086364eb92020a87ea610f Mon Sep 17 00:00:00 2001 From: Jacob Su Date: Sun, 17 Mar 2024 11:31:19 +0800 Subject: [PATCH] issue #204: fix get pthread id problem. --- src/ks_thread.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ks_thread.c b/src/ks_thread.c index 6f29c2c..ad446f9 100644 --- a/src/ks_thread.c +++ b/src/ks_thread.c @@ -77,7 +77,16 @@ KS_DECLARE(ks_pid_t) ks_thread_self_id(void) #elif KS_PLAT_LIN return syscall(SYS_gettid); #else - return pthread_self(); + uint64_t tid; + int r = pthread_threadid_np(NULL, &tid); + if (!r) { + return tid; + } else { + ks_log(KS_LOG_CRIT, "pthread_threadid_np error, return %d", r); + ks_log(KS_LOG_CRIT, "BACKTRACE:"); + ks_debug_dump_backtrace(); + abort(); + } #endif } @@ -165,10 +174,10 @@ static void *KS_THREAD_CALLING_CONVENTION thread_launch(void *args) if (thread->tag) SetThreadName(thread->id, thread->tag); #elif KS_PLAT_MAC - if (thread->tag && pthread_setname_np) + if (thread->tag && &pthread_setname_np) pthread_setname_np(thread->tag); #else - if (thread->tag && pthread_setname_np) + if (thread->tag && &pthread_setname_np) pthread_setname_np(pthread_self(), thread->tag); #endif