diff --git a/tokio/src/runtime/task/state.rs b/tokio/src/runtime/task/state.rs index da3e8d38d..2d3a1b5c4 100644 --- a/tokio/src/runtime/task/state.rs +++ b/tokio/src/runtime/task/state.rs @@ -252,9 +252,15 @@ impl State { /// Transitions the state to `NOTIFIED`. pub(super) fn transition_to_notified_by_ref(&self) -> TransitionToNotifiedByRef { self.fetch_update_action(|mut snapshot| { - if snapshot.is_complete() || snapshot.is_notified() { - // There is nothing to do in this case. + if snapshot.is_complete() { + // The complete state is final (TransitionToNotifiedByRef::DoNothing, None) + } else if snapshot.is_notified() { + // Even hough we have nothing to do in this branch, + // wake_by_ref() should synchronize-with the task starting execution, + // therefore we must use an Release store (with the same value), + // to pair with the Acquire in transition_to_running. + (TransitionToNotifiedByRef::DoNothing, Some(snapshot)) } else if snapshot.is_running() { // If the task is running, we mark it as notified, but we should // not submit as the thread currently running the future is