diff options
| author | Felix Raimundo <felix.raimundo@tweag.io> | 2017-05-07 16:01:47 +0200 |
|---|---|---|
| committer | Felix Raimundo <felix.raimundo@tweag.io> | 2017-05-07 16:01:47 +0200 |
| commit | 5573c4709cba7b3d5dc15c47239d1b1f32af4753 (patch) | |
| tree | 690eb1effcfd5cc6eeba771f90b9d3d8e691f8c1 /src/libstd/thread/mod.rs | |
| parent | d9628f9389319c1075d4a54a0a490226539cea81 (diff) | |
| download | rust-5573c4709cba7b3d5dc15c47239d1b1f32af4753.tar.gz rust-5573c4709cba7b3d5dc15c47239d1b1f32af4753.zip | |
Better example for `thread::unpark`.
Part of #29378
Diffstat (limited to 'src/libstd/thread/mod.rs')
| -rw-r--r-- | src/libstd/thread/mod.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index bdf7b1134bf..94a2c91858e 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -769,7 +769,7 @@ impl Thread { /// Atomically makes the handle's token available if it is not already. /// /// Every thread is equipped with some basic low-level blocking support, via - /// the [`park()`][park] function and the `unpark` method. These can be + /// the [`park()`][park] function and the `unpark()` method. These can be /// used as a more CPU-efficient implementation of a spinlock. /// /// See the [module doc][thread] for more detail. @@ -779,14 +779,21 @@ impl Thread { /// ``` /// use std::thread; /// - /// let handler = thread::Builder::new() + /// let parked_thread = thread::Builder::new() /// .spawn(|| { - /// let thread = thread::current(); - /// thread.unpark(); + /// println!("Parking thread"); + /// thread::park(); + /// println!("Thread unparked"); /// }) /// .unwrap(); /// - /// handler.join().unwrap(); + /// // Let some time pass for the thread to be spawned. + /// thread::sleep(Duration::from_millis(10)); + /// + /// println!("Unpark the thread"); + /// parked_thread.thread().unpark(); + /// + /// parked_thread.join().unwrap(); /// ``` /// /// [thread]: index.html |
