-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Concurrency: support draining the main queue in single threaded mode #35584
Conversation
When built in single threaded mode, the runtime does not use dispatch to queue the tasks. As a result, pumping the dispatch main queue will simply wait indefinitely. In the single threaded mode, simply halt execution and drain all pending tasks before returning. This allows forward progress in the single threaded mode.
@etcwilde not sure if this is the best way to handle this; perhaps in single-threaded mode, we should never arrive at this point and we should be changing the Swift path itself? |
@swift-ci please test |
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.
@etcwilde not sure if this is the best way to handle this; perhaps in single-threaded mode, we should never arrive at this point and we should be changing the Swift path itself?
I think this looks fine. It looks pretty much the same as how runAsyncAndBlock
is implemented for single-threaded mode.
I think we definitely want to allow concurrent code in single-threaded mode. Not quite following what you mean by "changing the Swift path itself", unless you mean that the maybe we have a different endpoint to call for running the async-main? Maybe? I would kind of like to keep logic for "draining the main queue and never returning" kept in one place, but if we get too many preprocessor macros going on here, it might make sense.
Yeah, I meant having a different end point coming in from the Swift side. Sounds like this approach is reasonable enough for now, so lets go with that. |
Build failed |
Build failed |
@swift-ci please smoke test Linux platform |
@swift-ci please test macOS platform |
Build failed |
@swift-ci please smoke test macOS platform |
When built in single threaded mode, the runtime does not use dispatch to
queue the tasks. As a result, pumping the dispatch main queue will
simply wait indefinitely. In the single threaded mode, simply halt
execution and drain all pending tasks before returning. This allows
forward progress in the single threaded mode.
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.