diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index e37cc7e963e10..4e49c485f109f 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -715,21 +715,32 @@ struct Inner { #[stable(feature = "rust1", since = "1.0.0")] /// A handle to a thread. /// +/// You can use it to identify a thread (by name, for example). Most of the +/// time, there is no need to directly create a `Thread` struct using the +/// constructor, instead you should use a function like `spawn` to create +/// new threads, see the docs of [`Builder`] and [`spawn`] for more. +/// /// # Examples /// /// ``` -/// use std::thread; -/// -/// let handler = thread::Builder::new() -/// .name("foo".into()) -/// .spawn(|| { -/// let thread = thread::current(); -/// println!("thread name: {}", thread.name().unwrap()); -/// }) -/// .unwrap(); -/// -/// handler.join().unwrap(); +/// use std::thread::Builder; +/// +/// for i in 0..5 { +/// let thread_name = format!("thread_{}", i); +/// Builder::new() +/// .name(thread_name) // Now you can identify which thread panicked +/// // thanks to the handle's name +/// .spawn(move || { +/// if i == 3 { +/// panic!("I'm scared!!!"); +/// } +/// }) +/// .unwrap(); +/// } /// ``` +/// [`Builder`]: ../../std/thread/struct.Builder.html +/// [`spawn`]: ../../std/thread/fn.spawn.html + pub struct Thread { inner: Arc, }