Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document expectations for Waker::wake #93966

Merged
merged 3 commits into from
May 25, 2022
Merged

document expectations for Waker::wake #93966

merged 3 commits into from
May 25, 2022

Conversation

rkuhn
Copy link
Contributor

@rkuhn rkuhn commented Feb 13, 2022

fixes #93961

Opened PR for a discussion on the precise wording.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 13, 2022
/// the runtime keeps running and the task is not finished it is expected that
/// each wake-up is followed by an invocation of `poll`, even in the absence of
/// other events. This makes it possible to yield to other tasks when running
/// potentially unbounded processing loops in order to maintain fairness.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this wording to me sounds like what you are getting at is that a call to wake() guarantees at least one call to poll (in the absence of Poll::Ready / runtime termination / panics / etc).

Maybe that's simpler than discussing coalescing etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that if I call cx.waker().wake_by_ref() twice in rapid succession, there will usually only be a single wake-up, hence “at least one call” is not correct. But with my proposed “is followed by” wording the coalescing can be left implicit if you find that more appropriate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. I think I had in mind that the interleaving is such that a wake() ensures at least one future call -- not necessarily each wake ensuring a distinct future call though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Guarantees there will be at least one call in the future" sounds correct to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, I pushed an improvement that focuses more on the essence.

@Mark-Simulacrum
Copy link
Member

r? @tmandry

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2022
Comment on lines +226 to +227
/// it possible to temporarily yield to other tasks while running potentially
/// unbounded processing loops.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessarily true; the executor could choose to poll this task again immediately instead of polling other tasks in a fair manner. See related discussion on #74335.

The above guarantee does say that you are allowed to yield without breaking your code (just not that it will do anything useful). I'm quite happy to add that to the documentation.

You may want to add the caveat I mentioned to the one you wrote below.

@JohnCSimon
Copy link
Member

ping from triage:
@rkuhn
Returning to you to address comments.

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR appears in the reviewer's backlog.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2022
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 4, 2022
@rkuhn
Copy link
Contributor Author

rkuhn commented May 4, 2022

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 4, 2022
@tmandry
Copy link
Member

tmandry commented May 24, 2022

@bors r+ rollup

I'm unclear on whether I should be approving this, but I don't want to let it sit any longer. @rust-lang/libs-api let me know if you would like to be r?'d on reviews like this in the future.

@bors
Copy link
Contributor

bors commented May 24, 2022

📌 Commit 3d808d5 has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 24, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 24, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#93966 (document expectations for Waker::wake)
 - rust-lang#97266 (Make weird name lints trigger behind cfg_attr)
 - rust-lang#97355 (Remove unused brush image)
 - rust-lang#97358 (Update minifier-rs version to 0.1.0)
 - rust-lang#97363 (Fix a small mistake in `SliceIndex`'s documentation)
 - rust-lang#97364 (Fix weird indentation in continue_keyword docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 33f45b1 into rust-lang:master May 25, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

clarify the semantics of core::task::Waker::wake()
7 participants