Add pthread_gettid_np for Android and glibc - #5359
Merged
Merged
Conversation
Collaborator
|
Some changes occurred in an Android module cc @maurer |
Contributor
Author
|
cc: @tgross35 |
tgross35
approved these changes
Aug 3, 2026
Returns the Linux TID for a given thread, unlike gettid, which only returns the id of the calling thread. This is useful for std in the thread spawn path: the parent can set the TID of the child it just created, whereas today the TID can only be read once the child itself starts running. The declaration is limited to Android and linux-gnu. musl and ohos do not re-export it. ctest is gated on the glibc version. The function was added in 2.42, so older glibc has no declaration to check against. Link: https://github.com/bminor/glibc/blob/d2097651cc57834dbfcaa102ddfacae0d86cfb66/sysdeps/nptl/pthread.h#L1320-L1322 Link: https://android.googlesource.com/platform/bionic/+/731631f300090436d7f5df80d50b6275c8c60a93/libc/include/pthread.h#173
valentynkit
force-pushed
the
pthread-gettid-np
branch
from
August 3, 2026 19:03
0fd6681 to
297c532
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link: https://github.com/bminor/glibc/blob/d2097651cc57834dbfcaa102ddfacae0d86cfb66/sysdeps/nptl/pthread.h#L1320-L1322
Link: https://android.googlesource.com/platform/bionic/+/731631f300090436d7f5df80d50b6275c8c60a93/libc/include/pthread.h#173
Description
Returns the Linux TID for a given thread, unlike
gettid, which only returns the id of the calling thread.This is useful for std in the thread spawn path: the parent can set the TID of the child it just created, whereas today the TID can only be read once the child itself starts running.
This came up while working on rust-lang/rust#160219, which fills the TID when the child starts running and explains what's missing to fill it from the parent right after creation.
libc already carries a by-handle TID query for Apple
pthread_gettid_np was added in glibc 2.42+; on Android it has been available since API level 21.
Checklist
libc-test/semverhave been updated*LASTor*MAXhave the standarddoc comment - not applicable
cargo test -p libc-test --target mytarget);especially relevant for platforms that may not be checked in CI
@rustbot label +stable-nominated