park():prohibit spurious wakeups in next park
should consume this notification, so prohibit spurious wakeups in next park
This commit is contained in:
parent
edae1cc38b
commit
7da469da8b
1 changed files with 10 additions and 2 deletions
|
@ -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"),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue