-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
task: Drop the join waker of a task eagerly when the JoinHandle gets dropped or the task completes #6986
base: master
Are you sure you want to change the base?
Conversation
f80d191
to
217b26d
Compare
dropped or the task completes Currently, the waker registered with a JoinHandle is not dropped until the task allocation is dropped. This behaviour may cause the memory allocated by a task to not be freed when in the case of two tasks awaiting each others JoinHandle. This commit changes the behaviour by actively dropping the waker when the JoinHandle gets dropped (or the task completes in some cases).
217b26d
to
163d841
Compare
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.
It may be nice to mention somewhere that JOIN_WAKER
represents whether the runtime needs to call wake_by_ref
, and not whether the waker field is set. This way, it makes intuitive sense that the runtime can unset JOIN_WAKER
without setting waker
to None
.
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 thought that it is not needed to add this because JOIN_WAKER
acts as an access control bit to the waker field.
But I could add it to the documentation as well to make the use cases for the JOIN_WAKER
bit more clear.
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.
Ah, yeah, the "control bit" wording is okay, but I think what I proposed would be even better.
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 added the following to the docs of the JOIN_WAKER
:
//! [...]After the runtime sets COMPLETE to one, it invokes the waker if there is one so in this
//! case when a task completes the `JOIN_WAKER` bit implicates to the runtime
//! whether it should invoke the waker or not. After the runtime is done with
//! using the waker during task completion, it unsets the `JOIN_WAKER` bit to give
//! the `JoinHandle` exclusive access again so that it is able to drop the waker
//! at a later point.
Would that be enough for you?
eca9c26
to
c96a70d
Compare
c96a70d
to
d457bbb
Compare
Motivation
Currently, the waker registered with a JoinHandle is not dropped until the task allocation is dropped. This behaviour may cause the memory allocated by a task to not be freed when in the case of two tasks awaiting each others JoinHandle.
See #6505 for more details.
Solution
To prevent this we need to actively drop the waker when the
JoinHandle
gets dropped (or the task completes in some cases).Closes #6505.