12 stable releases (4 major)

5.0.0 Oct 22, 2024
4.2.2 Jul 18, 2024
4.2.1 Oct 16, 2023
4.1.0 May 15, 2023
1.0.0 Mar 13, 2016

#49 in Debugging

Download history 121557/week @ 2024-08-01 131411/week @ 2024-08-08 132311/week @ 2024-08-15 121810/week @ 2024-08-22 116585/week @ 2024-08-29 125301/week @ 2024-09-05 119061/week @ 2024-09-12 122052/week @ 2024-09-19 128039/week @ 2024-09-26 125288/week @ 2024-10-03 126075/week @ 2024-10-10 134252/week @ 2024-10-17 125192/week @ 2024-10-24 127470/week @ 2024-10-31 144518/week @ 2024-11-07 111793/week @ 2024-11-14

533,327 downloads per month
Used in 1,038 crates (39 directly)

MIT/Apache

11KB
82 lines

Thread-ID

Get a unique ID for the current thread in Rust.

Crates.io version Documentation

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.

Example

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.

License

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.

Contributing

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.

Dependencies

~0–8MB
~60K SLoC