Skip to content

Add pthread_gettid_np for Android and glibc - #5359

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
valentynkit:pthread-gettid-np
Aug 3, 2026
Merged

Add pthread_gettid_np for Android and glibc#5359
tgross35 merged 1 commit into
rust-lang:mainfrom
valentynkit:pthread-gettid-np

Conversation

@valentynkit

Copy link
Copy Markdown
Contributor

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

  • Relevant tests in libc-test/semver have been updated
  • Commit messages permalink to headers for added or changed API
  • Placeholder or unstable values like *LAST or *MAX have the standard
    doc comment - not applicable
  • Tested locally (cargo test -p libc-test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in an Android module

cc @maurer

@rustbot rustbot added O-android O-gnu O-linux O-linux-like S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Aug 3, 2026
@valentynkit

Copy link
Copy Markdown
Contributor Author

cc: @tgross35

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please squash. Will just need a rebase to fix the docs job.

Also no need to ping, maintainers are subscribed already

View changes since this review

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
@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
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.

@tgross35

tgross35 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@tgross35
tgross35 enabled auto-merge August 3, 2026 19:05
@tgross35
tgross35 added this pull request to the merge queue Aug 3, 2026
Merged via the queue into rust-lang:main with commit 87e552e Aug 3, 2026
111 of 113 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-android O-gnu O-linux O-linux-like stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants