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

Carlos O'Donell carlos@redhat.com
Thu Jan 11 18:23:19 GMT 2024


On 1/11/24 01:10, Trevor Gross via Libc-help wrote:
> 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.

This is much more complicated than it seems at first :-)

Please read through:
Bug 27880 - Please provide a pthread pid accessor
https://sourceware.org/bugzilla/show_bug.cgi?id=27880

Discussion here:
https://inbox.sourceware.org/libc-alpha/6d79a213-0df2-be8e-3596-e010f366a34f@linaro.org/

I don't recommend this as a "first contribution" kind of patch.

Are you looking to start with libc development?

Are you looking for an initial project to work on?

-- 
Cheers,
Carlos.



More information about the Libc-help mailing list