This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Use pthread_threadid_np as thread ID on OS X
ClosedPublic

Authored by kubamracek on Apr 11 2016, 1:39 AM.

Details

Summary

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.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 53204.Apr 11 2016, 1:39 AM
kubamracek retitled this revision from to [sanitizer] Use pthread_threadid_np as thread ID on OS X.
kubamracek updated this object.
kubamracek added reviewers: dvyukov, glider, samsonov, kcc.
dvyukov added inline comments.Apr 11 2016, 2:08 AM
lib/sanitizer_common/sanitizer_mac.cc
233

Is it OK that the value is potentially truncated?

kubamracek added inline comments.Apr 11 2016, 11:28 AM
lib/sanitizer_common/sanitizer_mac.cc
233

Hm. It's really just an incrementing thread counter in the kernel. Truncating this can only be an issue after the system created 2^32 threads. This sounds unlikely.

On the other hand, would it be a problem to change GetTid to return u64?

dvyukov accepted this revision.Apr 11 2016, 11:36 AM
dvyukov edited edge metadata.
dvyukov added inline comments.
lib/sanitizer_common/sanitizer_mac.cc
233

Yeah, it's probably unlikely on a 32-bit system. And I think we use it only for reporting, so a truncated id should not break anything. Up to you.

This revision is now accepted and ready to land.Apr 11 2016, 11:36 AM
This revision was automatically updated to reflect the committed changes.