diff options
| author | Pslydhh <luouyuyou@gmail.com> | 2018-06-02 14:34:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-02 14:34:34 +0800 |
| commit | 7da469da8b9f389500d0dac17f67d8928386ef60 (patch) | |
| tree | 8a78b20a9838fb0422fa80e8939ed39a936f4959 /src/libstd/thread | |
| parent | edae1cc38b467518a8eea590c9c3e0c103b4ecb0 (diff) | |
| download | rust-7da469da8b9f389500d0dac17f67d8928386ef60.tar.gz rust-7da469da8b9f389500d0dac17f67d8928386ef60.zip | |
park():prohibit spurious wakeups in next park
should consume this notification, so prohibit spurious wakeups in next park
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 1b976b79b4c..d4ee172c961 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -796,7 +796,11 @@ pub fn park() { let mut m = thread.inner.lock.lock().unwrap(); match thread.inner.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { Ok(_) => {} - Err(NOTIFIED) => return, // notified after we locked + Err(NOTIFIED) => { + // should consume this notification, so prohibit spurious wakeups in next park... + thread.inner.state.store(EMPTY, SeqCst); + return; + }, // notified after we locked Err(_) => panic!("inconsistent park state"), } loop { @@ -882,7 +886,11 @@ pub fn park_timeout(dur: Duration) { let m = thread.inner.lock.lock().unwrap(); match thread.inner.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { Ok(_) => {} - Err(NOTIFIED) => return, // notified after we locked + Err(NOTIFIED) => { + // should consume this notification, so prohibit spurious wakeups in next park... + thread.inner.state.store(EMPTY, SeqCst); + return; + }, // notified after we locked Err(_) => panic!("inconsistent park_timeout state"), } |
