@@ -558,6 +558,23 @@ pub fn park_timeout(dur: Duration) {
558
558
/// A `ThreadId` is an opaque object that has a unique value for each thread
559
559
/// that creates one. `ThreadId`s do not correspond to a thread's system-
560
560
/// designated identifier.
561
+ ///
562
+ /// # Examples
563
+ ///
564
+ /// ```
565
+ /// #![feature(thread_id)]
566
+ ///
567
+ /// use std::thread;
568
+ ///
569
+ /// let handler = thread::Builder::new()
570
+ /// .spawn(|| {
571
+ /// let thread = thread::current();
572
+ /// let thread_id = thread.id();
573
+ /// })
574
+ /// .unwrap();
575
+ ///
576
+ /// handler.join().unwrap();
577
+ /// ```
561
578
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
562
579
#[ derive( Eq , PartialEq , Copy , Clone ) ]
563
580
pub struct ThreadId ( u64 ) ;
@@ -610,6 +627,22 @@ struct Inner {
610
627
#[ derive( Clone ) ]
611
628
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
612
629
/// A handle to a thread.
630
+ ///
631
+ /// # Examples
632
+ ///
633
+ /// ```
634
+ /// use std::thread;
635
+ ///
636
+ /// let handler = thread::Builder::new()
637
+ /// .name("foo".into())
638
+ /// .spawn(|| {
639
+ /// let thread = thread::current();
640
+ /// println!("thread name: {}", thread.name().unwrap());
641
+ /// })
642
+ /// .unwrap();
643
+ ///
644
+ /// handler.join().unwrap();
645
+ /// ```
613
646
pub struct Thread {
614
647
inner : Arc < Inner > ,
615
648
}
@@ -633,6 +666,21 @@ impl Thread {
633
666
/// Atomically makes the handle's token available if it is not already.
634
667
///
635
668
/// See the module doc for more detail.
669
+ ///
670
+ /// # Examples
671
+ ///
672
+ /// ```
673
+ /// use std::thread;
674
+ ///
675
+ /// let handler = thread::Builder::new()
676
+ /// .spawn(|| {
677
+ /// let thread = thread::current();
678
+ /// thread.unpark();
679
+ /// })
680
+ /// .unwrap();
681
+ ///
682
+ /// handler.join().unwrap();
683
+ /// ```
636
684
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
637
685
pub fn unpark ( & self ) {
638
686
let mut guard = self . inner . lock . lock ( ) . unwrap ( ) ;
@@ -643,6 +691,23 @@ impl Thread {
643
691
}
644
692
645
693
/// Gets the thread's unique identifier.
694
+ ///
695
+ /// # Examples
696
+ ///
697
+ /// ```
698
+ /// #![feature(thread_id)]
699
+ ///
700
+ /// use std::thread;
701
+ ///
702
+ /// let handler = thread::Builder::new()
703
+ /// .spawn(|| {
704
+ /// let thread = thread::current();
705
+ /// println!("thread id: {:?}", thread.id());
706
+ /// })
707
+ /// .unwrap();
708
+ ///
709
+ /// handler.join().unwrap();
710
+ /// ```
646
711
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
647
712
pub fn id ( & self ) -> ThreadId {
648
713
self . inner . id
0 commit comments