Skip to content

Enhance documentation on wake call memory ordering#157694

Open
xmh0511 wants to merge 9 commits into
rust-lang:mainfrom
xmh0511:main
Open

Enhance documentation on wake call memory ordering#157694
xmh0511 wants to merge 9 commits into
rust-lang:mainfrom
xmh0511:main

Conversation

@xmh0511

@xmh0511 xmh0511 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 10, 2026
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 10 candidates
  • Random selection from LawnGnome, Mark-Simulacrum, clarfonthey, jhpratt

@rust-log-analyzer

This comment has been minimized.

@xmh0511

xmh0511 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@Darksonn

It's probably sufficient to say that "the call to wake() happens-before the beginning of the call to poll()".

the call to wake() sounds like the whole wake() synchronizes with the beginning of the call to poll(). I cited a similar wording in the C++ standard, which is worded in this way:

Synchronization: The completion of the thread represented by *this synchronizes with ([intro.multithread]) the corresponding successful join() return.

I agree that"wake() return" or "the call to wake()" is indistinguishable for establishing happens-before. All evaluations that do not occur within a function invocation are either sequenced-before/after these that occur within the function invocation.

@xmh0511

xmh0511 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@Darksonn After thinking more, I think your wording is reasonable. Consider this a valid implementation of wake(pseudo code)

fn wak(&self){
   do_something1(); // #1
   self.flag.swap(1,AcqRel); // #2
   do_something2(); // #3
}

In this implementation, #2 synchronizes with the RMW operation that is sequenced before the call to poll(). That is, only these evaluations that are sequenced before #2 happen before the poll(). So, strictly speaking, the call expression wake() sequences before #2, it's reasonable to say it happens before the beginning of the call to poll(); however, wake() return does not.

BTW, the expression wake() itself means call to wake, saying call to wake() is a bit strange.

@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/task/wake.rs Outdated
Comment thread library/core/src/task/wake.rs Outdated
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
@rust-log-analyzer

This comment has been minimized.

@xmh0511 xmh0511 requested a review from Darksonn June 10, 2026 08:28
Comment thread library/core/src/task/wake.rs Outdated
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
@xmh0511 xmh0511 requested a review from Darksonn June 10, 2026 09:51
Comment thread library/alloc/src/task.rs Outdated
Comment thread library/core/src/task/wake.rs Outdated
Comment thread library/core/src/task/wake.rs Outdated
Comment thread library/core/src/task/wake.rs Outdated
xmh0511 and others added 2 commits June 11, 2026 09:46
Co-authored-by: Kevin Reid <kpreid@switchb.org>
Co-authored-by: Kevin Reid <kpreid@switchb.org>
@xmh0511 xmh0511 requested review from kpreid, lasiotus and orlp June 11, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants