Tracking Issue for thread_os_id
Nobody has claimed this yet.
- 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_idreturnsNone. The ACP describesNoneas 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_idunder alternatives, and the question of why that would be "more limited", given that "having to load aThreadis unnecessarily inefficient on platforms where the thread ID can be fetched directly", was left unanswered.std::threaddoes have an internalcurrent_os_id, but it returnsu64and 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.- Resolving based on https://github.com/rust-lang/rust/issues/160215#issuecomment-5145105691:
thread::current_os_idcan be useful but is less flexible, so we can consider it separately.
- Resolving based on https://github.com/rust-lang/rust/issues/160215#issuecomment-5145105691:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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