park():prohibit spurious wakeups in next park

should consume this notification, so prohibit spurious wakeups in next park
This commit is contained in:
Pslydhh 2018-06-02 14:34:34 +08:00 committed by GitHub
parent edae1cc38b
commit 7da469da8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"),
}