File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -713,22 +713,27 @@ struct Inner {
713
713
714
714
#[ derive( Clone ) ]
715
715
#[ 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.
717
719
///
718
720
/// # Examples
719
721
///
720
722
/// ```
721
723
/// use std::thread;
722
724
///
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
725
730
/// .spawn(|| {
726
- /// let thread = thread::current();
727
- /// println!("thread name: {}", thread.name().unwrap());
731
+ /// if i == 3 {
732
+ /// panic!("I'm scared!!!");
733
+ /// }
728
734
/// })
729
735
/// .unwrap();
730
- ///
731
- /// handler.join().unwrap();
736
+ /// }
732
737
/// ```
733
738
pub struct Thread {
734
739
inner : Arc < Inner > ,
You can’t perform that action at this time.
0 commit comments