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

rt: fix new yield_now behavior with block_in_place #5251

Merged
merged 1 commit into from Dec 2, 2022
Merged

Conversation

carllerche
Copy link
Member

PR #5223 changed the behavior of yield_now() to store yielded tasks and notify them after polling the resource drivers. This PR fixes two bugs with this new behavior when combined with block_in_place().

First, we must avoid freeing the deferred task queue when exiting a runtime if it is not the root runtime. Because block_in_place() allows a user to start a new runtime from within an existing task, this check is necessary.

Second, when a worker core is stolen from a thread during a block_in_place() call, we need to ensure that deferred tasks are notified.

PR #5223 changed the behavior of `yield_now()` to store yielded tasks
and notify them *after* polling the resource drivers. This PR fixes a
couple of bugs with this new behavior when combined with
`block_in_place()`.

First, we need to avoid freeing the deferred task queue when exiting a
runtime if it is *not* the root runtime. Because `block_in_place()`
allows a user to start a new runtime from within an existing task, this
check is necessary.

Second, when a worker core is stolen from a thread during a
`block_in_place()` call, we need to ensure that deferred tasks are
notified anyway.
@carllerche carllerche added C-bug Category: This is a bug. A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels Dec 1, 2022
@github-actions github-actions bot added the R-loom Run loom tests on this PR label Dec 1, 2022
// Catching panics on worker threads in tests is quite tricky. Instead, when
// debug assertions are enabled, we just abort the process.
#[cfg(debug_assertions)]
let _abort_on_panic = AbortOnPanic;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just for tests and hopefully catching issues sooner.

@carllerche carllerche merged commit d1b789f into master Dec 2, 2022
@carllerche carllerche deleted the fix-yield-now branch December 2, 2022 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-runtime Module: tokio/runtime R-loom Run loom tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants