Fix Display.sleep() race condition: make wake volatile, move reset before loop#34
Draft
Fix Display.sleep() race condition: make wake volatile, move reset before loop#34
Conversation
…fore loop The GTK Display.sleep() had a race condition where the `wake` boolean flag was reset to false inside the do-while loop (before each poll). If wakeThread() was called between loop iterations, the wake=true signal could be overwritten by wake=false, and the eventfd signal consumed by g_main_context_check(), causing the sleep loop to miss the wakeup and continue sleeping indefinitely. Fixes: 1. Make `wake` field volatile for cross-thread visibility 2. Move `wake = false` before the loop (reset once, not per iteration) 3. Update BusyIndicator to use asyncExec instead of wake() for CompletionStage completion (defense in depth) 4. Correct the misleading "Bug in GTK" comment - the issue was in SWT's own code, not in g_main_context_wakeup() 5. Add analysis documentation Fixes eclipse-platform#3044 Related: eclipse-platform#3053, eclipse-platform#3059, eclipse-platform#3060 Agent-Logs-Url: https://github.com/laeubi/eclipse.platform.swt/sessions/d50f4895-a7c1-40e0-991d-4121ed47a5e7 Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
laeubi
April 2, 2026 10:42
View session
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.
g_main_context_wakeupIs Maybe Not Buggy eclipse-platform/eclipse.platform.swt#3053 (g_main_context_wakeup investigation), sleep() does not react to thread interruption eclipse-platform/eclipse.platform.swt#3059 (sleep interrupt), Display#wake must likley be volatile eclipse-platform/eclipse.platform.swt#3060 (volatile wake)wakeboolean flagwake = falsebefore the loop and makingwakevolatile