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

Add hints to yield_now to allow schedulers to deprioritize a yielding thread #18

Merged
merged 1 commit into from
Apr 13, 2021

Conversation

jamesbornholt
Copy link
Member

Tasks that implement busy-wait loops or other infinite loops are a fairness
issue for schedulers like PCT, which will run a thread indefinitely until it
blocks. This change makes both sync and async versions of yield_now act as
a hint to the scheduler that the current task should be deprioritized. Only
the PCT scheduler acts on this hint, by moving the current task to the lowest
priority. We could also make the DFS scheduler react to this hint by not
allowing it to re-schedule the current task immediately, but that would be
unsound.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


asynch::block_on(async move {
while count.load(Ordering::SeqCst) < NUM_TASKS {
asynch::yield_now().await;
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a variant of this test without the yield, showing that PCT finds the schedule where the test panics because we hit the max_steps limit?

.collect::<Vec<_>>();

while count.load(Ordering::SeqCst) < NUM_THREADS {
thread::yield_now();
Copy link
Member

Choose a reason for hiding this comment

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

Same as above -- add a variant of the test that panics without the yield?

Copy link
Member

@jorajeev jorajeev left a comment

Choose a reason for hiding this comment

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

Looks good -- maybe add tests that show PCT finds the unfair executions?

…ng thread

Tasks that implement busy-wait loops or other infinite loops are a fairness
issue for schedulers like PCT, which will run a thread indefinitely until it
blocks. This change makes both sync and async versions of `yield_now` act as
a hint to the scheduler that the current task should be deprioritized. Only
the PCT scheduler acts on this hint, by moving the current task to the lowest
priority. We could also make the DFS scheduler react to this hint by not
allowing it to re-schedule the current task immediately, but that would be
unsound.
@jamesbornholt
Copy link
Member Author

Good idea, done.

@jorajeev jorajeev merged commit 4ff98e4 into awslabs:main Apr 13, 2021
@jamesbornholt jamesbornholt deleted the pct-yield branch April 14, 2021 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants