Skip to content

[Concurrency] Run async main code on main thread #36239

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

Merged

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Mar 2, 2021

This patch moves the actual running of the main code onto the main
thread by making it part of the main actor. This should be more
consistent with what folks are expecting.

Resolves: rdar://73255194

@etcwilde etcwilde requested a review from DougGregor March 2, 2021 20:17
@etcwilde
Copy link
Member Author

etcwilde commented Mar 2, 2021

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

etcwilde commented Mar 2, 2021

I'm going to add a check in the test/Concurrency/Runtime/mainactor.swift to verify that we're actually running on the main thread.

@etcwilde etcwilde force-pushed the ewilde/run-async-main-on-main-thread branch from 86d5eed to 4576825 Compare March 2, 2021 20:46
@etcwilde
Copy link
Member Author

etcwilde commented Mar 2, 2021

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

etcwilde commented Mar 2, 2021

@swift-ci please smoke test windows

@etcwilde
Copy link
Member Author

etcwilde commented Mar 2, 2021

@swift-ci please smoke test windows

etcwilde added 2 commits March 2, 2021 22:36
This patch moves the actual running of the main code onto the main
thread by making it part of the main actor. This should be more
consistent with what folks are expecting.
This patch adds a check to verify that we're running on the main thread
when running the async-main function.
@etcwilde etcwilde force-pushed the ewilde/run-async-main-on-main-thread branch from 4576825 to 12c3eb2 Compare March 3, 2021 06:36
@etcwilde
Copy link
Member Author

etcwilde commented Mar 3, 2021

@swift-ci please smoke test

@@ -77,6 +79,11 @@ actor A {
@main struct RunIt {
static func main() async {
print("starting")
if checkIfMainQueue(expectedAnswer: true) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't force Windows to be running on the main thread, then this will probably fail on Windows, or at least not be all that reliable. :(

@etcwilde
Copy link
Member Author

etcwilde commented Mar 3, 2021

@swift-ci please smoke test macOS

@etcwilde etcwilde merged commit 2ee7a32 into swiftlang:main Mar 3, 2021
@etcwilde etcwilde deleted the ewilde/run-async-main-on-main-thread branch March 3, 2021 17:47
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