rust-lang / rust-lang/rust

Tracking Issue for thread_os_id

Open
#160,215 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-unimplemented T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(thread_os_id)]

This is a tracking issue for Thread::os_id, which returns the OS-level thread id of the thread a handle refers to. That is the id that shows up in tools like ps and top, debuggers, and crash logs. ThreadId is under the control of the standard library and has no guaranteed relationship to it, so the two cannot be used interchangeably.

Public API
// std::thread

impl Thread {
    pub fn os_id(&self) -> Option<u64>;
}

None means the platform has no OS thread id, or has no way to read it, or the handle belongs to a spawned thread that has not started running yet. That last case is not one of the reasons the ACP gave, so it is an unresolved question below.

Steps / History
  • ACP: rust-lang/libs-team#635
  • Implementation: #160219
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • A handle for a spawned thread exists before the thread does, and the implementation has the thread record its own id once it starts running, so until then os_id returns None. The ACP describes None as meaning "the platform does not support it", so this is an extra reason a caller can see it. As far as I can tell that is fine for an unstable feature, but worth confirming before stabilization.
  • The ACP listed a free thread::current_os_id under alternatives, and the question of why that would be "more limited", given that "having to load a Thread is unnecessarily inefficient on platforms where the thread ID can be fetched directly", was left unanswered. std::thread does have an internal current_os_id, but it returns u64 and falls back to the Rust thread id, so it is not the shape a public function would want. Out of scope here either way, but still open.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the std:🧵:Thread::os_id API, the implementation in #160219, and the ACP in rust-lang/libs-team#635. Review the unresolved question about None for threads that have not started, then confirm the intended semantics and determine the remaining FCP and stabilization steps.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.