Skip to content

Commit 08514b4

Browse files
author
Christian Poveda
committed
rewrote the thread struct docs
1 parent c7e724a commit 08514b4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/libstd/thread/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,22 +713,27 @@ struct Inner {
713713

714714
#[derive(Clone)]
715715
#[stable(feature = "rust1", since = "1.0.0")]
716-
/// A handle to a thread.
716+
/// A handle to a thread, its just an abstract reference and as such
717+
/// it can be used to identify a thread (by name, for example). In most
718+
/// usage cases, this struct is not used directly.
717719
///
718720
/// # Examples
719721
///
720722
/// ```
721723
/// use std::thread;
722724
///
723-
/// let handler = thread::Builder::new()
724-
/// .name("foo".into())
725+
/// for i in 0..5 {
726+
/// let thread_name = format!("thread_{}", i);
727+
/// thread::Builder::new()
728+
/// .name(thread_name) // Now you can identify which thread panicked
729+
/// // thanks to the handle's name
725730
/// .spawn(|| {
726-
/// let thread = thread::current();
727-
/// println!("thread name: {}", thread.name().unwrap());
731+
/// if i == 3 {
732+
/// panic!("I'm scared!!!");
733+
/// }
728734
/// })
729735
/// .unwrap();
730-
///
731-
/// handler.join().unwrap();
736+
/// }
732737
/// ```
733738
pub struct Thread {
734739
inner: Arc<Inner>,

0 commit comments

Comments
 (0)