@@ -652,8 +652,8 @@ pub fn park_timeout(dur: Duration) {
652
652
/// A unique identifier for a running thread.
653
653
///
654
654
/// A `ThreadId` is an opaque object that has a unique value for each thread
655
- /// that creates one. `ThreadId`s do not correspond to a thread's system-
656
- /// designated identifier.
655
+ /// that creates one. `ThreadId`s are not guaranteed to correspond to a thread's
656
+ /// system- designated identifier.
657
657
///
658
658
/// # Examples
659
659
///
@@ -662,17 +662,15 @@ pub fn park_timeout(dur: Duration) {
662
662
///
663
663
/// use std::thread;
664
664
///
665
- /// let handler = thread::Builder::new()
666
- /// .spawn(|| {
667
- /// let thread = thread::current();
668
- /// let thread_id = thread.id();
669
- /// })
670
- /// .unwrap();
665
+ /// let other_thread = thread::spawn(|| {
666
+ /// thread::current().id()
667
+ /// });
671
668
///
672
- /// handler.join().unwrap();
669
+ /// let other_thread_id = other_thread.join().unwrap();
670
+ /// assert!(thread::current().id() != other_thread_id);
673
671
/// ```
674
672
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
675
- #[ derive( Eq , PartialEq , Copy , Clone ) ]
673
+ #[ derive( Eq , PartialEq , Clone , Copy , Hash , Debug ) ]
676
674
pub struct ThreadId ( u64 ) ;
677
675
678
676
impl ThreadId {
@@ -701,13 +699,6 @@ impl ThreadId {
701
699
}
702
700
}
703
701
704
- #[ unstable( feature = "thread_id" , issue = "21507" ) ]
705
- impl fmt:: Debug for ThreadId {
706
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
707
- f. pad ( "ThreadId { .. }" )
708
- }
709
- }
710
-
711
702
////////////////////////////////////////////////////////////////////////////////
712
703
// Thread
713
704
////////////////////////////////////////////////////////////////////////////////
@@ -795,14 +786,12 @@ impl Thread {
795
786
///
796
787
/// use std::thread;
797
788
///
798
- /// let handler = thread::Builder::new()
799
- /// .spawn(|| {
800
- /// let thread = thread::current();
801
- /// println!("thread id: {:?}", thread.id());
802
- /// })
803
- /// .unwrap();
789
+ /// let other_thread = thread::spawn(|| {
790
+ /// thread::current().id()
791
+ /// });
804
792
///
805
- /// handler.join().unwrap();
793
+ /// let other_thread_id = other_thread.join().unwrap();
794
+ /// assert!(thread::current().id() != other_thread_id);
806
795
/// ```
807
796
#[ unstable( feature = "thread_id" , issue = "21507" ) ]
808
797
pub fn id ( & self ) -> ThreadId {
0 commit comments