mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
Fix race condition related bugs (#243)
* Fix races. This mostly pulls in changes from rust-lang-nursery/futures-rs#881, but also updates Registration to be a bit more obvious as to what is going on. * Reduce spurious wakeups caused by Reactor This patch adds an ABA guard on token values before registering them with Mio. This allows catching token reuse and avoid the notification. This is needed for OS X as the notification is used to determine that a TCP connect has completed. A spurious notification can potentially cause write failures.
This commit is contained in:
@@ -936,9 +936,10 @@ impl Future for Shutdown {
|
||||
type Error = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<(), ()> {
|
||||
use futures::task;
|
||||
trace!("Shutdown::poll");
|
||||
|
||||
self.inner().shutdown_task.task1.register();
|
||||
self.inner().shutdown_task.task1.register_task(task::current());
|
||||
|
||||
if 0 != self.inner().num_workers.load(Acquire) {
|
||||
return Ok(Async::NotReady);
|
||||
|
||||
@@ -222,13 +222,13 @@ impl Task {
|
||||
let actual = self.inner().state.compare_and_swap(
|
||||
Idle.into(),
|
||||
Scheduled.into(),
|
||||
Relaxed).into();
|
||||
AcqRel).into();
|
||||
|
||||
match actual {
|
||||
Idle => return true,
|
||||
Running => {
|
||||
let actual = self.inner().state.compare_and_swap(
|
||||
Running.into(), Notified.into(), Relaxed).into();
|
||||
Running.into(), Notified.into(), AcqRel).into();
|
||||
|
||||
match actual {
|
||||
Idle => continue,
|
||||
|
||||
Reference in New Issue
Block a user