Crates.io | thread-id |
lib.rs | thread-id |
version | 5.0.0 |
source | src |
created_at | 2016-03-13 21:01:16.768851 |
updated_at | 2024-10-22 18:19:23.071829 |
description | Get a unique thread ID |
homepage | |
repository | https://github.com/ruuda/thread-id |
max_upload_size | |
id | 4446 |
size | 30,537 |
Get a unique ID for the current thread in Rust.
For diagnostics and debugging it can often be useful to get an ID that is different for every thread. Until Rust 1.14, the standard library did not expose a way to do that, hence this crate.
use std::thread;
use thread_id;
let handle = thread::spawn(move || {
println!("spawned thread has id {}", thread_id::get());
});
println!("main thread has id {}", thread_id::get());
handle.join().unwrap();
This will print two different numbers.
Thread-ID is licensed under either the Apache 2.0 license, or the MIT license, at your option. It may be used in free software as well as closed-source applications, both for commercial and non-commercial use under the conditions given in the license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache 2.0 license, shall be dual licensed as above, without any additional terms or conditions.