mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
Fix a race in thread wakeup (#459)
This commit is contained in:
committed by
Carl Lerche
parent
dbefa67058
commit
7fb579c667
@@ -133,8 +133,8 @@ impl Inner {
|
||||
None => self.condvar.wait(m).unwrap(),
|
||||
};
|
||||
|
||||
// Transition back to idle. If the state has transitions dto `NOTIFY`,
|
||||
// this will consume that notification
|
||||
// Transition back to idle. If the state has transitioned to `NOTIFY`,
|
||||
// this will consume that notification.
|
||||
self.state.store(IDLE, SeqCst);
|
||||
|
||||
// Explicitly drop the mutex guard. There is no real point in doing it
|
||||
@@ -155,10 +155,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, SeqCst) {
|
||||
// Transition to NOTIFY
|
||||
match self.state.swap(NOTIFY, SeqCst) {
|
||||
SLEEP => {}
|
||||
_ => return,
|
||||
NOTIFY => return,
|
||||
IDLE => return,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
// Wakeup the sleeper
|
||||
|
||||
Reference in New Issue
Block a user