diff options
| author | Ibraheem Ahmed <ibraheem@ibraheem.ca> | 2023-06-20 20:05:31 -0400 |
|---|---|---|
| committer | Ibraheem Ahmed <ibraheem@ibraheem.ca> | 2023-06-20 20:05:31 -0400 |
| commit | bf27f12d941b2aea125bd629c1f30feaacf41cc6 (patch) | |
| tree | 12b129b94fb6fe05bc6a212f70f0d8f657449733 /library/std/src/thread | |
| parent | e9868ef8df9817802a0aaf0695e83c1e45783842 (diff) | |
| download | rust-bf27f12d941b2aea125bd629c1f30feaacf41cc6.tar.gz rust-bf27f12d941b2aea125bd629c1f30feaacf41cc6.zip | |
relaxed orderings in `thread::park` example
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/mod.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 0f8b9c76688..e9d94ba425a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -893,7 +893,8 @@ pub fn sleep(dur: Duration) { /// /// Note that being unblocked does not imply a call was made to `unpark`, because /// wakeups can also be spurious. For example, a valid, but inefficient, -/// implementation could have `park` and `unpark` return immediately without doing anything. +/// implementation could have `park` and `unpark` return immediately without doing anything, +/// making *all* wakeups spurious. /// /// # Examples /// @@ -908,7 +909,7 @@ pub fn sleep(dur: Duration) { /// let parked_thread = thread::spawn(move || { /// // We want to wait until the flag is set. We *could* just spin, but using /// // park/unpark is more efficient. -/// while !flag2.load(Ordering::Acquire) { +/// while !flag2.load(Ordering::Relaxed) { /// println!("Parking thread"); /// thread::park(); /// // We *could* get here spuriously, i.e., way before the 10ms below are over! @@ -925,7 +926,7 @@ pub fn sleep(dur: Duration) { /// // There is no race condition here, if `unpark` /// // happens first, `park` will return immediately. /// // Hence there is no risk of a deadlock. -/// flag.store(true, Ordering::Release); +/// flag.store(true, Ordering::Relaxed); /// println!("Unpark the thread"); /// parked_thread.thread().unpark(); /// |
