Skip to content

Commit

Permalink
park():prohibit spurious wakeups in next park
Browse files Browse the repository at this point in the history
should consume this notification, so prohibit spurious wakeups in next park
  • Loading branch information
Pslydhh authored Jun 2, 2018
1 parent edae1cc commit 7da469d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
}

Expand Down

0 comments on commit 7da469d

Please sign in to comment.