W3cubDocs

/Rust

Function current_id

pub fn current_id() -> ThreadId
🔬This is a nightly-only experimental API. (current_thread_id #147194)

Gets the unique identifier of the thread which invokes it.

Calling this function may be more efficient than accessing the current thread id through the current thread handle. i.e. thread::current().id().

This function will always succeed, will always return the same value for one thread and is guaranteed not to call the global allocator.

Examples

#![feature(current_thread_id)]

use std::thread;

let other_thread = thread::spawn(|| {
    thread::current_id()
});

let other_thread_id = other_thread.join().unwrap();
assert_ne!(thread::current_id(), other_thread_id);

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/fn.current_id.html