On linux a thread is identified by a pthread_t or a TID. I'm looking for bridges between these two kinds of thread ids:
- given a
pthread_tcan I get it'sTID? apparently not without hacking in pthread's internals :( but i'm still asking in case someone has a clean way to do it. - given a
TID(orPID), can I get apthread_thandle to it ?
Because the term "thread id" is ambiguous in this context (and in the documentation), a bit of background:
The POSIX pthread API defines a
pthread_ttype, all functions that query/act on a thread use apthread_targument, and we can get such a handle e.g. withpthread_self(). The documentation calls these "thread ids", but here I call them handles to disambiguate, because multiple differentpthread_tvalues may represent the same thread, hence the need forpthread_equal(pthread_t, pthread_t).On the other hand, on linux at least, there is a concept of
TIDs or thread ids. One can get the currentTIDwith a system call:syscall(SYS_gettid). TheTIDhas a few interesting properties such as being unique to a thread, and comparable toPIDs, which allows to easily identify the main thread, etc.