-
-
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
rt: pop at least one task from inject queue #5908
Conversation
When attempting to pull a batch of tasks from the injection queue, ensure we set the cap to at least one.
The current behavior is not incorrect but will result in less-than-optimal execution behavior. |
// Take at least one task since the first task is returned directly | ||
// and nto pushed onto the local queue. | ||
let n = usize::max(1, n); |
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.
Seems like you should add one to cap
in the usize::min
above instead, no?
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 could... I thought it would be clearer to split it out w/ a comment.
// Take at least one task since the first task is returned directly | ||
// and nto pushed onto the local queue. | ||
let n = usize::max(1, n); | ||
|
||
let mut synced = worker.handle.shared.synced.lock(); | ||
// safety: passing in the correct `inject::Synced`. | ||
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) }; |
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.
In fact, maybe do this and drop the plus one in the first branch of usize::min
?
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) }; | |
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n + 1) }; |
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.
But that isn't the same. We don't want to always add 1
; we want a min of 1
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'll let you go for the solution you prefer.
When pulling a batch of tasks from the injection queue, ensure we set the cap to at least one.