diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-05-03 18:33:59 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-03 18:33:59 -0400 |
| commit | 9f06dfb4515b096b65980f7f93e53b70a1c583b3 (patch) | |
| tree | d76698f6c1f736e78f5d99fb7a4bcc4a02a18d03 /src/libstd/thread | |
| parent | 8305394b4c32c2576bb02a026c05f01c96f46d92 (diff) | |
| parent | cf521211a13ccb7e8ea25af97d0efc3abe6d9070 (diff) | |
| download | rust-9f06dfb4515b096b65980f7f93e53b70a1c583b3.tar.gz rust-9f06dfb4515b096b65980f7f93e53b70a1c583b3.zip | |
Rollup merge of #41543 - z1mvader:master, r=steveklabnik
Rewrote the thread struct docs https://github.com/rust-lang/rust/issues/29378
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 33 |
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>, } |
