From 7da469da8b9f389500d0dac17f67d8928386ef60 Mon Sep 17 00:00:00 2001 From: Pslydhh Date: Sat, 2 Jun 2018 14:34:34 +0800 Subject: [PATCH 1/3] park():prohibit spurious wakeups in next park should consume this notification, so prohibit spurious wakeups in next park --- src/libstd/thread/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 1b976b79b4c98..d4ee172c96192 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -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"), } From 151e41ff0c2769b5bc9f0d37ae37136fb4fcb7e0 Mon Sep 17 00:00:00 2001 From: Pslydhh Date: Sat, 2 Jun 2018 15:36:23 +0800 Subject: [PATCH 2/3] remove trailing whitespace remove trailing whitespace --- src/libstd/thread/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index d4ee172c96192..d76107e99090c 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -796,10 +796,10 @@ pub fn park() { let mut m = thread.inner.lock.lock().unwrap(); match thread.inner.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { Ok(_) => {} - Err(NOTIFIED) => { + Err(NOTIFIED) => { // should consume this notification, so prohibit spurious wakeups in next park... - thread.inner.state.store(EMPTY, SeqCst); - return; + thread.inner.state.store(EMPTY, SeqCst); + return; }, // notified after we locked Err(_) => panic!("inconsistent park state"), } @@ -886,10 +886,10 @@ 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) => { + Err(NOTIFIED) => { // should consume this notification, so prohibit spurious wakeups in next park... - thread.inner.state.store(EMPTY, SeqCst); - return; + thread.inner.state.store(EMPTY, SeqCst); + return; }, // notified after we locked Err(_) => panic!("inconsistent park_timeout state"), } From b352d2d167f1de4ed8a6da3405dc90fe9d646204 Mon Sep 17 00:00:00 2001 From: Pslydhh Date: Sat, 2 Jun 2018 15:59:54 +0800 Subject: [PATCH 3/3] removes tabs --- src/libstd/thread/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index d76107e99090c..e6d052a458f6a 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -797,10 +797,9 @@ pub fn park() { match thread.inner.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { Ok(_) => {} Err(NOTIFIED) => { - // should consume this notification, so prohibit spurious wakeups in next park... - thread.inner.state.store(EMPTY, SeqCst); - return; - }, // notified after we locked + thread.inner.state.store(EMPTY, SeqCst); + return; + } // should consume this notification, so prohibit spurious wakeups in next park. Err(_) => panic!("inconsistent park state"), } loop { @@ -887,10 +886,9 @@ pub fn park_timeout(dur: Duration) { match thread.inner.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { Ok(_) => {} Err(NOTIFIED) => { - // should consume this notification, so prohibit spurious wakeups in next park... - thread.inner.state.store(EMPTY, SeqCst); - return; - }, // notified after we locked + thread.inner.state.store(EMPTY, SeqCst); + return; + } // should consume this notification, so prohibit spurious wakeups in next park. Err(_) => panic!("inconsistent park_timeout state"), }