-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
rt: add support for non-send closures for thread (un)parking #7420
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
base: master
Are you sure you want to change the base?
Conversation
be90205
to
eeb45d3
Compare
c124e08
to
4f8b562
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.
We need a test to make sure callbacks will not be executed when using the Handle::block_on
.
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.
afaiu, we can only test this for on_thread_unpark
. we can't test this for on_thread_park
because if the task parks itself inside Handle::block_on
, there's nothing that can call unpark()
for the task.
4f8b562
to
fde0d15
Compare
Add support for non `Send`+`Sync` closures for thread parking and unparking callbacks when using a `LocalRuntime`. Since a `LocalRuntime` will always run its tasks on the same thread, its safe to accept a non `Send`+`Sync` closure. Signed-off-by: Sanskar Jaiswal <[email protected]>
fde0d15
to
453dbd2
Compare
Add support for non
Send
+Sync
closures for thread parking and unparking callbacks when using aLocalRuntime
. Since aLocalRuntime
will always run its tasks on the same thread, its safe to accept a nonSend
+Sync
closure.Motivation
Since
LocalRuntime
can run nonSend
+Sync
functions, we should accept thread parking/unparking callbacks that do not implementSend
andSync
.Solution
Add two methods on
LocalOptions
,on_thread_park
andon_thread_unpark
that accept aFn() + 'static
. These callbacks are then converted intoFn() + Send + Sync + 'static
. This requires unsafe code, but unsafe is acceptable here because of the behaviour ofLocalRuntime
fixes #7370