std-method

Thread::id: opaque thread identity

A thread ID supports equality and hashing. Do not treat its debug spelling as an OS process identifier or as a portable integer. A name is descriptive, not necessarily unique. Expected stdout (not executed): true Common mistake: Parsing the Debug representation to get an OS thread ID.

Formal Syntax & Structure

rust syntaxrust
thread.id() -> ThreadId

Working Example

Example Snippetrust
fn main() {    let h = std::thread::spawn(|| std::thread::current().id());    let expected = h.thread().id();    println!("{}", h.join().unwrap() == expected);}
Rust Reference