From b9feac8d6841bc7933f3d9d508f4179800d4d579 Mon Sep 17 00:00:00 2001 From: Adam Ning Date: Thu, 18 Sep 2025 19:41:23 +0800 Subject: [PATCH] runtime: use release in `wake_by_ref()` even if already woken (#7622) (cherry picked from commit 67869be3d75c58f9b84bc469e00439b70aff0516) --- tokio/src/runtime/task/state.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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