From e5b26815138ece649747f094962c18c232855f8a Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Tue, 31 Jul 2018 05:46:46 +0200 Subject: [PATCH] Fix a race in thread wakeup (#507) --- tokio-executor/src/park.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tokio-executor/src/park.rs b/tokio-executor/src/park.rs index 13713261c..4f278fdd3 100644 --- a/tokio-executor/src/park.rs +++ b/tokio-executor/src/park.rs @@ -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