Skip to content

LocalWaker and Waker cleanups #54732

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

Merged
merged 1 commit into from
Oct 10, 2018
Merged

LocalWaker and Waker cleanups #54732

merged 1 commit into from
Oct 10, 2018

Conversation

cramertj
Copy link
Member

@cramertj cramertj commented Oct 1, 2018

r? @aturon

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 1, 2018
@TimNN
Copy link
Contributor

TimNN commented Oct 9, 2018

Ping from triage @aturon / @rust-lang/libs: This PR requires your review.

/// `Waker` is nearly identical to `LocalWaker`, but is threadsafe
/// (implements `Send` and `Sync`).
#[inline]
pub fn as_waker(&self) -> &Waker {
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually safe? With scoped threads it seems like you could use this to pass a LocalWaker to another thread as a &Waker?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, you can! And that's totally safe, because you can only call .wake() on the inner UnsafeWake in a Wake-- you can't call .wake_local().

@aturon
Copy link
Member

aturon commented Oct 10, 2018

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 10, 2018

📌 Commit 00e0565 has been approved by aturon

@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 Oct 10, 2018
@bors
Copy link
Collaborator

bors commented Oct 10, 2018

⌛ Testing commit 00e0565 with merge 5af0bb8...

bors added a commit that referenced this pull request Oct 10, 2018
LocalWaker and Waker cleanups

r? @aturon
@bors
Copy link
Collaborator

bors commented Oct 10, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: aturon
Pushing 5af0bb8 to master...

@bors bors merged commit 00e0565 into rust-lang:master Oct 10, 2018
@cramertj cramertj deleted the waker branch October 10, 2018 22:34
@ghost
Copy link

ghost commented Nov 22, 2018

@cramertj Bikeshedding... 🚲🚲🚲

I find names will_wake, will_wake_local, and will_wake_nonlocal confusing. Aren't those functions essentially just equality tests? Why not implement Eq for Waker and LocalWaker?

Compare: waker.will_wake_local(local_waker) vs waker == local_waker.

@cramertj
Copy link
Member Author

@stjepang There was a lot of debate back in the day about this, which ended in rust-lang/futures-rs#689 and rust-lang/futures-rs#1236, in an effort to prevent people from thinking of two different Tasks as being "equivalent" merely because their notify() methods wake the same top-level future. With the addition of LocalWaker, it's also kind of wrong to consider them "equivalent" since they may perform different behaviors, but will result in waking up the same task (however, this doesn't actually work today since will_wake checks for equality of the fat pointers and so has false negatives).

@ghost
Copy link

ghost commented Nov 27, 2018

@cramertj Ah I see the problem, thanks for the explanation!

Still, judging by the name, I had no idea what a.will_wake(b) actually does. My intuition was that there's some kind of promise that a will wake b in the future, but that's not the case.

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants