File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -769,7 +769,7 @@ impl Thread {
769
769
/// Atomically makes the handle's token available if it is not already.
770
770
///
771
771
/// Every thread is equipped with some basic low-level blocking support, via
772
- /// the [`park()`][park] function and the `unpark` method. These can be
772
+ /// the [`park()`][park] function and the `unpark() ` method. These can be
773
773
/// used as a more CPU-efficient implementation of a spinlock.
774
774
///
775
775
/// See the [module doc][thread] for more detail.
@@ -779,14 +779,21 @@ impl Thread {
779
779
/// ```
780
780
/// use std::thread;
781
781
///
782
- /// let handler = thread::Builder::new()
782
+ /// let parked_thread = thread::Builder::new()
783
783
/// .spawn(|| {
784
- /// let thread = thread::current();
785
- /// thread.unpark();
784
+ /// println!("Parking thread");
785
+ /// thread::park();
786
+ /// println!("Thread unparked");
786
787
/// })
787
788
/// .unwrap();
788
789
///
789
- /// handler.join().unwrap();
790
+ /// // Let some time pass for the thread to be spawned.
791
+ /// thread::sleep(Duration::from_millis(10));
792
+ ///
793
+ /// println!("Unpark the thread");
794
+ /// parked_thread.thread().unpark();
795
+ ///
796
+ /// parked_thread.join().unwrap();
790
797
/// ```
791
798
///
792
799
/// [thread]: index.html
You can’t perform that action at this time.
0 commit comments