Skip to content

Commit

Permalink
Rollup merge of rust-lang#41543 - z1mvader:master, r=steveklabnik
Browse files Browse the repository at this point in the history
Rewrote the thread struct docs

rust-lang#29378
  • Loading branch information
frewsxcv committed May 3, 2017
2 parents 8305394 + cf52121 commit 9f06dfb
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down

0 comments on commit 9f06dfb

Please sign in to comment.