[PATCH 1/3] Linux: Add the pthread_gettid_np function

Florian Weimer fweimer@redhat.com
Tue Mar 11 14:12:29 GMT 2025


> On Tue, Mar 11, 2025 at 8:54 AM enh <enh@google.com> wrote:
>>
>> On Tue, Mar 11, 2025 at 7:06 AM Florian Weimer <fweimer@redhat.com> wrote:
>> >
>> > There is no good match for this function in other libcs.
>> > Bionic has pthread_gettid without error checking (and without the
>> > _np suffix), but with the same prototype.  Other systems use
>> > a pointer argument for the value.
>>
>> you must have been looking at an 11+ year old version of bionic :-)
>>
>> no LP64 version of Android has pthread_gettid() (though ILP32 will do
>> until it's removed, for app compat), and every version of Android
>> since at least 2014's "L"/api level 21 has pthread_gettid_np().
>>
>> i'm not sure what error checking you think is missing?
>
> ah, that's probably also an artifact of looking at an ancient
> implementation: i just looked and the historical __pthread_gettid()
> [note the leading underscores, which i'd forgotten about] did indeed
> just cast the pthread_t to the internal thread type and dereference it
> ... though it seems like your implementation does the same? (i know
> glibc has thread caching which bionic doesn't, but i assumed you had
> some cache eviction policy?)

We only have imprefect error checking in glibc, too.  What I meant that
there isn't anything that prevents return 0.  I assume you are returning
the TID field that is overwritten by the kernel once the thread exits.

Thanks,
Florian



More information about the Libc-alpha mailing list