-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add Wake trait for safe construction of Wakers. #68700
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06ede35
Add Wake trait for safe construction of Wakers.
withoutboats d8a835f
Add `wake_trait` feature directive to std
withoutboats c9acdb0
Improve safety implementation, fix typos
withoutboats ede03a4
typo
withoutboats 3ae74ca
More explicit; CFG on atomic pointer
withoutboats a4875a7
Update src/libstd/lib.rs
withoutboats caff9f9
Update src/liballoc/task.rs
withoutboats 32f5724
Apply suggestions from code review
withoutboats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Apply suggestions from code review
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
- Loading branch information
commit 32f5724e8ac35e5a314313c6053ff46702223b27
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
futures::task::ArcWake
has the opposite defaulted method. Is there a reason to assume that implementations would commonly need to own theArc
instead of being able to wake through a shared reference?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my experience working on romio/juliex and reading the tokio source, the standard executor model is to re-enqueue the task on some TLS or global queue (which means it must have ownership), and the standard reactor model is to store an
Option<Waker>
and then call.take().unwrap().wake()
. IMO the default in futures is backwards, and would result in naive implementations making an additional unnecessary ref count increment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion about this either way-- I can definitely imagine arguments on either side. The reason I did it the other way in futures-rs was that I imagined implementations which only needed by-reference waking would implement just
wake
not realizing that that would result in awake_by_ref
method which cloned unnecessarily. In practice, I don't think either case is too big of an issue.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, either way I think its a chance of an incorrectly implemented executor leading to one extra incr/decr on wakeup - a trivial and easily fixable problem.
But I do think the more likely scenario is that they do need ownership of the arc, rather than that they don't (the only point of it being by arc is to cheaply enqueue on wake up after all), and I thought our choice to name the fns
wake
andwake_by_ref
was tied up in this assumption (that wake would be the default one).