[libc-commits] [libc] [libc] Add an extension macro to get numerical thread id (PR #195202)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Tue May 5 13:07:59 PDT 2026
kaladron wrote:
> > Both glibc and musl appear to cast the thread pointer to the TCB to unsigned long and use that as the value of pthread_t, which avoids exposing internals, structs, or anything else. Do we have a need to do anything different? I think I'm missing what problem this is trying to solve.
>
> I think that's what this PR is effectively doing as well? Only instead of having `typedef unsigned long pthread_t;` in public header, we ask the caller to call a private API to get an integer representation of opaque pthread_t.
Right - but why? If everyone is expecting an unsigned long, why not give that to them?
There isn't a standard way of doing this so we have the freedom, but all the work in the linuxthreads and early NPTL era was about not giving people any sort interface because everyone misused it in weird ways.
We completely control what's under the pointer and explicitly don't expose it beyond the contract that it's unique.
It's the "why" that I'm missing for this.
https://github.com/llvm/llvm-project/pull/195202
More information about the libc-commits
mailing list