@@ -652,8 +652,8 @@ pub fn park_timeout(dur: Duration) {
652652/// A unique identifier for a running thread.
653653///
654654/// 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.
657657///
658658/// # Examples
659659///
@@ -662,17 +662,15 @@ pub fn park_timeout(dur: Duration) {
662662///
663663/// use std::thread;
664664///
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+ /// });
671668///
672- /// handler.join().unwrap();
669+ /// let other_thread_id = other_thread.join().unwrap();
670+ /// assert!(thread::current().id() != other_thread_id);
673671/// ```
674672#[ unstable( feature = "thread_id" , issue = "21507" ) ]
675- #[ derive( Eq , PartialEq , Copy , Clone ) ]
673+ #[ derive( Eq , PartialEq , Clone , Copy , Hash , Debug ) ]
676674pub struct ThreadId ( u64 ) ;
677675
678676impl ThreadId {
@@ -701,13 +699,6 @@ impl ThreadId {
701699 }
702700}
703701
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-
711702////////////////////////////////////////////////////////////////////////////////
712703// Thread
713704////////////////////////////////////////////////////////////////////////////////
@@ -795,14 +786,12 @@ impl Thread {
795786 ///
796787 /// use std::thread;
797788 ///
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+ /// });
804792 ///
805- /// handler.join().unwrap();
793+ /// let other_thread_id = other_thread.join().unwrap();
794+ /// assert!(thread::current().id() != other_thread_id);
806795 /// ```
807796 #[ unstable( feature = "thread_id" , issue = "21507" ) ]
808797 pub fn id ( & self ) -> ThreadId {
0 commit comments