Fix a race in thread wakeup (#507)

This commit is contained in:
Stjepan Glavina
2018-07-30 20:46:46 -07:00
committed by Carl Lerche
parent 629c9f0698
commit e5b2681513
+5 -3
View File
@@ -288,10 +288,12 @@ impl Inner {
// The other half is sleeping, this requires a lock
let _m = self.mutex.lock().unwrap();
// Transition from SLEEP -> NOTIFY
match self.state.compare_and_swap(SLEEP, NOTIFY, Ordering::SeqCst) {
// Transition to NOTIFY
match self.state.swap(NOTIFY, Ordering::SeqCst) {
SLEEP => {}
_ => return,
NOTIFY => return,
IDLE => return,
_ => unreachable!(),
}
// Wakeup the sleeper