about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorStephen M. Coakley <me@stephencoakley.com>2017-04-01 22:17:59 -0500
committerStephen M. Coakley <me@stephencoakley.com>2017-04-03 01:23:52 -0500
commit282029526646fc93cd8bc098191c4e110a4c4938 (patch)
tree8a953426a6c401e07653bd2be0d07849375e69e9 /src/libstd/thread
parent5e122f59ba23494d460466cca53c71646d99c767 (diff)
downloadrust-282029526646fc93cd8bc098191c4e110a4c4938.tar.gz
rust-282029526646fc93cd8bc098191c4e110a4c4938.zip
Derive Hash for ThreadId + better example
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index edf928d6106..21f9757ad11 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -652,8 +652,8 @@ pub fn park_timeout(dur: Duration) {
 /// A unique identifier for a running thread.
 ///
 /// A `ThreadId` is an opaque object that has a unique value for each thread
-/// that creates one. `ThreadId`s do not correspond to a thread's system-
-/// designated identifier.
+/// that creates one. `ThreadId`s are not guaranteed to correspond to a thread's
+/// system-designated identifier.
 ///
 /// # Examples
 ///
@@ -662,17 +662,15 @@ pub fn park_timeout(dur: Duration) {
 ///
 /// use std::thread;
 ///
-/// let handler = thread::Builder::new()
-///     .spawn(|| {
-///         let thread = thread::current();
-///         let thread_id = thread.id();
-///     })
-///     .unwrap();
+/// let other_thread = thread::spawn(|| {
+///     thread::current().id()
+/// });
 ///
-/// handler.join().unwrap();
+/// let other_thread_id = other_thread.join().unwrap();
+/// assert!(thread::current().id() != other_thread_id);
 /// ```
 #[unstable(feature = "thread_id", issue = "21507")]
-#[derive(Eq, PartialEq, Copy, Clone)]
+#[derive(Clone, Copy, Eq, PartialEq, Hash)]
 pub struct ThreadId(u64);
 
 impl ThreadId {
@@ -795,14 +793,12 @@ impl Thread {
     ///
     /// use std::thread;
     ///
-    /// let handler = thread::Builder::new()
-    ///     .spawn(|| {
-    ///         let thread = thread::current();
-    ///         println!("thread id: {:?}", thread.id());
-    ///     })
-    ///     .unwrap();
+    /// let other_thread = thread::spawn(|| {
+    ///     thread::current().id()
+    /// });
     ///
-    /// handler.join().unwrap();
+    /// let other_thread_id = other_thread.join().unwrap();
+    /// assert!(thread::current().id() != other_thread_id);
     /// ```
     #[unstable(feature = "thread_id", issue = "21507")]
     pub fn id(&self) -> ThreadId {