ThreadId in std::thread - Rust (original) (raw)

Struct ThreadId

1.19.0 · Source

pub struct ThreadId(/* private fields */);

Expand description

A unique identifier for a running thread.

A ThreadId is an opaque object that uniquely identifies each thread created during the lifetime of a process. ThreadIds are guaranteed not to be reused, even when a thread terminates. ThreadIds are under the control of Rust’s standard library and there may not be any relationship betweenThreadId and the underlying platform’s notion of a thread identifier – the two concepts cannot, therefore, be used interchangeably. A ThreadIdcan be retrieved from the id method on a Thread.

§Examples

use std::thread;

let other_thread = thread::spawn(|| {
    thread::current().id()
});

let other_thread_id = other_thread.join().unwrap();
assert!(thread::current().id() != other_thread_id);

Source§

Source

🔬This is a nightly-only experimental API. (thread_id_value #67939)

This returns a numeric identifier for the thread identified by thisThreadId.

As noted in the documentation for the type itself, it is essentially an opaque ID, but is guaranteed to be unique for each thread. The returned value is entirely opaque – only equality testing is stable. Note that it is not guaranteed which values new threads will return, and this may change across Rust versions.

1.19.0 · Source§

1.19.0 · Source§

1.19.0 · Source§

1.19.0 · Source§

Source§

Tests for self and other values to be equal, and is used by ==.

1.0.0 · Source§

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

1.19.0 · Source§

1.19.0 · Source§

1.19.0 · Source§

§

§

§

§

§

§