macOS: Run tasks synchronously on main thread instead of asynchronously #2574
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.
Part of #2464.
Historically we've been using
Queue::main().exec_async
(dispatch_async_f
), tracing back to b492564 which was included in #853. This works by putting the closure onto a queue, and then executing it on the main thread at a later point (in spirit similar to doing athread::spawn
and forget).While this works, it is very brittle, since any code that may run after such a call will read stale data until the event loop has run once more. Instead, we'll use
dispatch_sync_f
, which will block the calling thread until the main thread has had a chance to run it, meaning that whatever state changes may have happened are visible right after any call.I've left out the things that affect the fullscreen logic, since that is more gnarly, and would be nice to have as a separate commit to allow easier bisection if something goes wrong. Will follow up with another PR for that.
CHANGELOG.md
if knowledge of this change could be valuable to usersNote: I strongly suspect the reason that
dispatch_async_f
was originally chosen overdispatch_sync_f
was becausedispatch_async_f
works on the main thread out-of-the-box - though @francesca64 may be able to clarify on that.