TID in the files and on the stack trace not matching
In the stack trace, we see something like this:
*** SIGSEGV (@0x149d) received by PID 22298 (TID 0x36087700) from PID 5277; stack trace: ***
In the files, we see:
I1107 17:38:43.965498 22378 xx.cc:nnn]
22378 is supposed to be the thread id and so is: 0x36087700. I skimmed over the code and seems like 2 different functions are used to compute the values:
(a) https://github.com/google/glog/blob/a34226ca94be8faae363b0599e5c4cdb7767774a/src/signalhandler.cc#L211 (b) https://github.com/google/glog/blob/f4dd77ae6b8e5f8e1323c929e81dbc40ff58fc7b/src/utilities.cc#L259
What is the relation between the two? How do I know which TID caused the crash?
The difference is expected as per gettid documentation:
The thread ID returned by this call is not the same thing as a POSIX thread ID (i.e., the opaque value returned by pthread_self(3)).
The answer to your question depends on how you intend to identify your threads.
@sergiud I want to look at which thread caused the crash. Is there a way to know that? Out of curiosity, why not call the same function at both places?
I want to look at which thread caused the crash. Is there a way to know that?
I'm not sure I understand what are you asking given you have two IDs at your disposal. Choose the one that suits your tooling.
Out of curiosity, why not call the same function at both places?
This is likely an inconsistency that arose over time. You are welcome to provide a fix.
I'm not sure I understand what are you asking given you have two IDs at your disposal. Choose the one that suits your tooling.
@sergiud We have a stack trace of the crash with an ID: 0x36087700. I want to see the log files and see what this thread was doing before crashing. In a multi-threaded env. this can be really helpful.
This is likely an inconsistency that arose over time. You are welcome to provide a fix.
Which function is preferable: GetTID or pthread_self? I will see if I can fix it.
For consistency and information gain both functions should be used.