@@ -648,6 +648,23 @@ pub fn park_timeout(dur: Duration) {
648
648
/// A `ThreadId` is an opaque object that has a unique value for each thread
649
649
/// that creates one. `ThreadId`s do not correspond to a thread's system-
650
650
/// designated identifier.
651
+ ///
652
+ /// # Examples
653
+ ///
654
+ /// ```
655
+ /// #![feature(thread_id)]
656
+ ///
657
+ /// use std::thread;
658
+ ///
659
+ /// let handler = thread::Builder::new()
660
+ /// .spawn(|| {
661
+ /// let thread = thread::current();
662
+ /// let thread_id = thread.id();
663
+ /// })
664
+ /// .unwrap();
665
+ ///
666
+ /// handler.join().unwrap();
667
+ /// ```
651
668
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
652
669
#[ derive( Eq , PartialEq , Copy , Clone ) ]
653
670
pub struct ThreadId ( u64 ) ;
@@ -700,6 +717,22 @@ struct Inner {
700
717
#[ derive( Clone ) ]
701
718
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
702
719
/// A handle to a thread.
720
+ ///
721
+ /// # Examples
722
+ ///
723
+ /// ```
724
+ /// use std::thread;
725
+ ///
726
+ /// let handler = thread::Builder::new()
727
+ /// .name("foo".into())
728
+ /// .spawn(|| {
729
+ /// let thread = thread::current();
730
+ /// println!("thread name: {}", thread.name().unwrap());
731
+ /// })
732
+ /// .unwrap();
733
+ ///
734
+ /// handler.join().unwrap();
735
+ /// ```
703
736
pub struct Thread {
704
737
inner : Arc < Inner > ,
705
738
}
@@ -723,6 +756,21 @@ impl Thread {
723
756
/// Atomically makes the handle's token available if it is not already.
724
757
///
725
758
/// See the module doc for more detail.
759
+ ///
760
+ /// # Examples
761
+ ///
762
+ /// ```
763
+ /// use std::thread;
764
+ ///
765
+ /// let handler = thread::Builder::new()
766
+ /// .spawn(|| {
767
+ /// let thread = thread::current();
768
+ /// thread.unpark();
769
+ /// })
770
+ /// .unwrap();
771
+ ///
772
+ /// handler.join().unwrap();
773
+ /// ```
726
774
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
727
775
pub fn unpark ( & self ) {
728
776
let mut guard = self . inner . lock . lock ( ) . unwrap ( ) ;
@@ -733,6 +781,23 @@ impl Thread {
733
781
}
734
782
735
783
/// Gets the thread's unique identifier.
784
+ ///
785
+ /// # Examples
786
+ ///
787
+ /// ```
788
+ /// #![feature(thread_id)]
789
+ ///
790
+ /// use std::thread;
791
+ ///
792
+ /// let handler = thread::Builder::new()
793
+ /// .spawn(|| {
794
+ /// let thread = thread::current();
795
+ /// println!("thread id: {:?}", thread.id());
796
+ /// })
797
+ /// .unwrap();
798
+ ///
799
+ /// handler.join().unwrap();
800
+ /// ```
736
801
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
737
802
pub fn id ( & self ) -> ThreadId {
738
803
self . inner . id
0 commit comments