Struct std::thread::ThreadId1.19.0[][src]

pub struct ThreadId(_);
Expand description

正在运行的线程的唯一标识符。

ThreadId 是一个不透明的对象,它唯一的标识了在进程生命周期期中创建的每个线程。ThreadIds 保证不会被重用,即使线程终止时也是如此。 ThreadId 受 Rust 标准库的控制,ThreadId 和底层平台的线程标识符概念之间可能没有任何关系 – 因此,这两个概念不能互换使用。

可以从 Thread 上的 id 方法中检索 ThreadId

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);
Run

Implementations

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

这将返回此 ThreadId 标识的线程的数字标识符。

如类型本身的文档中所述,它本质上是一个不透明的 ID,但可以保证每个线程都是唯一的。 返回的值是完全不透明的 - 仅相等测试是稳定的。 请注意,不能保证新线程将返回哪些值,并且在 Rust 版本之间可能会改变。

Trait Implementations

返回值的副本。 Read more

source 执行复制分配。 Read more

使用给定的格式化程序格式化该值。 Read more

将该值输入给定的 HasherRead more

将这种类型的切片送入给定的 Hasher 中。 Read more

此方法测试 selfother 值是否相等,并由 == 使用。 Read more

此方法测试 !=

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

获得所有权后的结果类型。

从借用的数据创建拥有的数据,通常是通过克隆。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。