about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-08-01 10:12:38 +0200
committerGitHub <noreply@github.com>2018-08-01 10:12:38 +0200
commit06b91a4901621455999ff77f1b63c8c64f4eae56 (patch)
tree760978d7587ca59f1870778f2004de8eed3f8caa /src/libstd/thread
parentdafe33524a8646d02b2e35ad616ac1bdbf88da16 (diff)
parent5f87f78b148c1825b92514580f47866c5ae67fbb (diff)
downloadrust-06b91a4901621455999ff77f1b63c8c64f4eae56.tar.gz
rust-06b91a4901621455999ff77f1b63c8c64f4eae56.zip
Rollup merge of #52771 - matklad:patch-1, r=kennytm
Clarify thread::park semantics

It took me quite some time to realize that the example is not actually racy, so let's clarify it? :-)
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index ae804ad409e..bbe80df7e8b 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -731,7 +731,8 @@ const NOTIFIED: usize = 2;
 ///   specifying a maximum time to block the thread for.
 ///
 /// * The [`unpark`] method on a [`Thread`] atomically makes the token available
-///   if it wasn't already.
+///   if it wasn't already. Because the token is initially absent, [`unpark`]
+///   followed by [`park`] will result in the second call returning immediately.
 ///
 /// In other words, each [`Thread`] acts a bit like a spinlock that can be
 /// locked and unlocked using `park` and `unpark`.
@@ -766,6 +767,8 @@ const NOTIFIED: usize = 2;
 /// // Let some time pass for the thread to be spawned.
 /// thread::sleep(Duration::from_millis(10));
 ///
+/// // There is no race condition here, if `unpark`
+/// // happens first, `park` will return immediately.
 /// println!("Unpark the thread");
 /// parked_thread.thread().unpark();
 ///