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

Thread ID on macOS #182

Closed
jgehring opened this issue Apr 28, 2017 · 1 comment
Closed

Thread ID on macOS #182

jgehring opened this issue Apr 28, 2017 · 1 comment

Comments

@jgehring
Copy link

I'm using glog on macOS and noticed that gettid(2) is used to obtain a "thread ID". However, on macOS this function is quite different from Linux and the output is not very useful for logging as it represents the uid and gid of a thread (see the explanation at http://elliotth.blogspot.co.uk/2012/04/gettid-on-mac-os.html, for example). As a result, multiple runs of the same program will usually end up with the same "thread ID" which makes analyzing logs quite painful. The linked blog post also mentions that it's possible to use pthread_threadid_np(3) starting from 10.5. Did you ever consider using this?

@pwnall
Copy link
Member

pwnall commented May 7, 2017

Another reason to switch: on OSX 10.12, using syscall results in a deprecation warning.

/Users/pwnall/workspace/glog/src/utilities.cc:254:17: warning: 'syscall' is deprecated: first deprecated in
      macOS 10.12 - syscall(2) is unsupported; please switch to a supported interface. For SYS_kdebug_trace use
      kdebug_signpost(). [-Wdeprecated-declarations]
    pid_t tid = syscall(__NR_gettid);
                ^
/usr/include/unistd.h:733:6: note: 'syscall' has been explicitly marked deprecated here
int      syscall(int, ...);
         ^
1 warning generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants