RFC: A way to get a TID from a pthread_t handler

Trevor Gross tmgross@umich.edu
Thu Jan 11 06:10:18 GMT 2024


Hello,

It seems like there isn't a good way to get the thread ID from a
pthread_t. If you are within the thread then you can call gettid(),
but there is no public API to get a spawned thread's TID after calling
pthread_create().

This value is stored in the pthread, so a new public function could
just be a basic getter:

    pid_t pthread_gettid(pthread_t threadid)
    {
      struct pthread *pd = (struct pthread *) threadid;
      return pd->tid;
    }

Would an addition like this likely get accepted? Or is there anything
overlooked about an easier way to recover the spawned thread's TID?

I could submit a patch, but require instruction on where this should live.

Thanks,
Trevor Gross


More information about the Libc-help mailing list