[PATCH] D18951: [sanitizer] Use pthread_threadid_np as thread ID on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 01:39:36 PDT 2016


kubabrecka created this revision.
kubabrecka added reviewers: dvyukov, glider, samsonov, kcc.
kubabrecka added subscribers: llvm-commits, zaks.anna, dcoughlin.

Let's use pthread_threadid_np which returns a more reasonable ID than pthread_self (which is actually a stack pointer).  The numbers from pthread_threadid_np are already used in other tools, e.g. in LLDB, and often appear in logs, so it's much more useful than pthread_self.

http://reviews.llvm.org/D18951

Files:
  lib/sanitizer_common/sanitizer_mac.cc

Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -230,7 +230,9 @@
 }
 
 uptr GetTid() {
-  return reinterpret_cast<uptr>(pthread_self());
+  uint64_t tid;
+  pthread_threadid_np(nullptr, &tid);
+  return tid;
 }
 
 void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18951.53204.patch
Type: text/x-patch
Size: 439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160411/41de2ad1/attachment.bin>


More information about the llvm-commits mailing list