Fix GCD deadlock on sync queue draw#113
Merged
Merged
Conversation
* src/macappkit.m (set_global_focus_view_frame): set identifier key on drawing queue for easy identification. (mac_draw_queue_sync): Do not dispatch empty block if already running from drawing queue.
This was referenced Oct 25, 2025
Owner
Author
|
I have had no recurrences of the issue in #78, so I am again cautiously optimistic that this is the right fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TLDR: A queue attempting to flush itself from the "inside" with a call to
dispatch_syncdeadlocks, so don't do that.Another attempt to fix the dreaded (but rare) GCD draw deadlock, that often (but not always) occurs on waking from sleep. See #78.
Here we assume the problem arises from a serial queue deadlock which occurs when a block from the queue running on the main GUI thread attempts to use
dispatch_syncon the same queue.So an asynchronous block on the
global_focus_drawing_queuetries to "flush" the queue, usingdispatch_syncto quickly wait for it to complete all its submitted blocks. But if this happens on the main thread,dispatch_syncis waiting for the queue to drain, and the currently executing block on the selfsame queue is waiting fordispatch_syncto complete: deadlock!Apparently this isn't a modern approach to drain GCD queues, but I kept it intact, and simply do nothing to sync if we are calling in to the same queue.
See also #86 for another (failed) attempt.
drawing queue for easy identification.
(mac_draw_queue_sync): Do not dispatch empty block if already running
from drawing queue.