-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Execute tasks scheduled at the same time in order on EmbeddedEventLoop #1540
Conversation
I mean...this is not actually true. Ultimately we delegate to This is not inherently a reason to refuse to make this change, but it's worth bearing in mind that there is absolutely no promise that tasks execute in any particular order. As a related note, this patch actually affects all scheduled tasks. This is a strict change from the behaviour of @weissi and @normanmaurer, where do you land here? Is it valuable to have |
@Lukasa what you're saying is definitely correct. We could hit this issue in the real world too. I'm happy with merging this and filing an issue that we should also add an insertion counter atomic and use that as a tie breaker if we have two tasks with equal ready times. |
Currently with our Big Dumb Lock it doesn't even need to be atomic: we take a look to enqueue tasks irregardless, so we can always just use that lock to guard the counter. |
Interesting; thanks for the details.
If we don't accept this change then we should state this explicitly in the documentation. |
@glbrntt I'd say: Let's take this & file a bug on NIO |
Works for me. |
hit #1545 |
@swift-nio-bot test this please |
Motivation: `EmbeddedEventLoop` executes scheduled tasks in their run-time order. If multiple tasks are scheduled for the same time then the order in which they are eventually executed is undefined. Since `execute` defers to scheduling a task for "now" it is possible for tasks to be executed out of order if `run()` is not called between each execute. In "real" event loops this isn't an issue because the system time must advance between each call to `execute`. Modifications: - Add a 'insertionOrder' to `EmbeddedScheduledTask`; use it to break ties when comparing two tasks with the same run time - Add a task counter to `EmbeddedEventLoop` which is used to provide an insertion order when scheduling tasks. Result: - EmbeddedEventLoop will `execute` tasks in order
Ping @weissi for review |
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.
Thank you! LGTM, sorry for the delay, thought I had done this one already 😭
Motivation:
EmbeddedEventLoop
executes scheduled tasks in their run-time order.If multiple tasks are scheduled for the same time then the order in
which they are eventually executed is undefined.
Since
execute
defers to scheduling a task for "now" it is possible fortasks to be executed out of order if
run()
is not called between eachexecute.
In "real" event loops this isn't an issue because the system time must
advance between each call to
execute
.Modifications:
EmbeddedScheduledTask
; use it to breakties when comparing two tasks with the same run time
EmbeddedEventLoop
which is used to provide aninsertion order when scheduling tasks.
Result:
execute
tasks in order