Skip to content

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

Merged
jorajeev merged 1 commit into
awslabs:mainfrom
jamesbornholt:pct-yield
Apr 13, 2021
Merged

Add hints to yield_now to allow schedulers to deprioritize a yielding thread#18
jorajeev merged 1 commit into
awslabs:mainfrom
jamesbornholt:pct-yield

Conversation

@jamesbornholt

Copy link
Copy Markdown
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.

@jamesbornholt jamesbornholt requested a review from jorajeev April 10, 2021 18:54
Comment thread tests/asynch/pct.rs Outdated

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

Copy link
Copy Markdown
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?

Comment thread tests/basic/pct.rs Outdated
.collect::<Vec<_>>();

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

Copy link
Copy Markdown
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?

@jorajeev jorajeev left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

Good idea, done.

@jamesbornholt jamesbornholt requested a review from jorajeev April 13, 2021 16:10
@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