about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-05-03 23:05:07 +0000
committerbors <bors@rust-lang.org>2017-05-03 23:05:07 +0000
commitb16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad (patch)
treee8fa6a2c0127f43d06a1e4fe7788c3cce852fab0 /src/libstd/thread
parent2d4ed8e0cbe2c5f3763273a5d8f6b15119473ba7 (diff)
parente20b2823303ddb145ce58286abeb67d4c017ccf0 (diff)
downloadrust-b16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad.tar.gz
rust-b16c7a235fa0f57fed6b7ec13ffd3cff1bcdd9ad.zip
Auto merge of #41735 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #41543, #41600, #41715, #41720, #41721, #41730
- Failed merges:
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index e37cc7e963e..4e49c485f10 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<Inner>,
 }