Fix UI thread main loop cancellation from another thread on macOS #12579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Ensure that the UI thread main loop is stopped.
What is the current behavior?
Cancelling the UI thread main loop from a different thread does not really stop the loop on macOS.
What is the updated/expected behavior with this PR?
Cancelling the UI thread main loop from a different thread stops the loop on macOS.
How was the solution implemented (if it's not obvious)?
When canceling the UI thread main loop from another thread on macOS,
dispatch_async()
is used to post the work,[NSApp stop:nil]
, into the loop. However this will not stop the loop as it doesn't result in the posting of anNSEvent
object (see https://developer.apple.com/documentation/appkit/nsapplication/1428473-stop for details). This PR posts the object to ensure the loop is stopped.This PR also fixes an issue that the
Running
flag is set too early.Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues