Skip to content

Commit 4899b76

Browse files
frostyplanetADD-SP
authored andcommitted
runtime: use release in wake_by_ref() even if already woken
1 parent f020b5c commit 4899b76

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tokio/src/runtime/task/state.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,15 @@ impl State {
252252
/// Transitions the state to `NOTIFIED`.
253253
pub(super) fn transition_to_notified_by_ref(&self) -> TransitionToNotifiedByRef {
254254
self.fetch_update_action(|mut snapshot| {
255-
if snapshot.is_complete() || snapshot.is_notified() {
256-
// There is nothing to do in this case.
255+
if snapshot.is_complete() {
256+
// The complete state is final
257257
(TransitionToNotifiedByRef::DoNothing, None)
258+
} else if snapshot.is_notified() {
259+
// Even hough we have nothing to do in this branch,
260+
// wake_by_ref() should synchronize-with the task starting execution,
261+
// therefore we must use an Release store (with the same value),
262+
// to pair with the Acquire in transition_to_running.
263+
(TransitionToNotifiedByRef::DoNothing, Some(snapshot))
258264
} else if snapshot.is_running() {
259265
// If the task is running, we mark it as notified, but we should
260266
// not submit as the thread currently running the future is

0 commit comments

Comments
 (0)