Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #204: fix get pthread id problem. #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/ks_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
suzp1984 marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down