diff options
| author | Ralf Jung <post@ralfj.de> | 2018-11-22 10:54:04 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-11-22 10:54:04 +0100 |
| commit | 2d46ae7c37a779fe993687e753b7c544bb26dc38 (patch) | |
| tree | 05f9b58b90c74d78c791cb19e19bdff58b2e27b3 /src/libstd | |
| parent | 4bec59c93baa71d599a616fda9f1180febb08386 (diff) | |
| download | rust-2d46ae7c37a779fe993687e753b7c544bb26dc38.tar.gz rust-2d46ae7c37a779fe993687e753b7c544bb26dc38.zip | |
expand thread::park explanation
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/thread/mod.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 8a845efd413..99f8fa390d2 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -806,9 +806,13 @@ const NOTIFIED: usize = 2; /// In other words, each [`Thread`] acts a bit like a spinlock that can be /// locked and unlocked using `park` and `unpark`. /// +/// Notice that it would be a valid (but inefficient) implementation to make both [`park`] and +/// [`unpark`] NOPs that return immediately. Being unblocked does not imply +/// any synchronization with someone that unparked this thread, it could also be spurious. +/// /// The API is typically used by acquiring a handle to the current thread, /// placing that handle in a shared data structure so that other threads can -/// find it, and then `park`ing. When some desired condition is met, another +/// find it, and then `park`ing in a loop. When some desired condition is met, another /// thread calls [`unpark`] on the handle. /// /// The motivation for this design is twofold: @@ -829,6 +833,7 @@ const NOTIFIED: usize = 2; /// .spawn(|| { /// println!("Parking thread"); /// thread::park(); +/// // We *could* get here spuriously, i.e., way before the 10ms below are over! /// println!("Thread unparked"); /// }) /// .unwrap(); |
