Skip to content

Tracking Issue for thread_os_id #160215

Description

@valentynkit

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

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.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions