Fix deadlock in beginJob when compiled debug#269
Open
Copilot wants to merge 2 commits into
Open
Conversation
The deadlock was caused by two issues: 1. Lock ordering: beginJob() held m_ while creating XThreadTimer (which acquires gSystemMutex internally), while the app thread could hold gSystemMutex (inside ProcessEvents) and try to acquire m_ via a timer callback - classic ABBA deadlock. 2. Bare cv_.wait() without predicate: susceptible to missed notifications if the signal was sent before the wait began. Fix: - Add appStarted_ and eveSetupDone_ boolean state flags - Use predicate-based cv_.wait() to handle missed notifications - Don't hold m_ during XThreadTimer creation to avoid lock ordering issue
Copilot
AI
changed the title
[WIP] Fix EventDisplay hang in beginJob when compiled debug
Fix deadlock in beginJob when compiled debug
May 29, 2026
brownd1978
requested changes
May 29, 2026
Contributor
brownd1978
left a comment
There was a problem hiding this comment.
This PR does not change the behavior: Mu2eEventDisplay complied debug still hangs in beginJob at line 273.
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.
Debug-compiled EventDisplay deadlocks in
beginJob()atcv_.wait(lock). GDB shows only 2 threads with the app thread apparently never reaching its event loop.Root cause: ABBA lock ordering between
m_(held bybeginJob) andgSystemMutex(acquired insideXThreadTimerconstructor viaR__LOCKGUARD2). The app thread holdsgSystemMutexingSystem->ProcessEvents()while timer callbacks attempt to acquirem_. Debug timing makes this race deterministic. Additionally, barecv_.wait()without a predicate loses notifications if the signal arrives before the wait begins.Changes:
beginJob()to only holdm_duringcv_.wait(), not duringXThreadTimerconstruction — eliminates lock ordering cycleappStarted_andeveSetupDone_predicate flags for the two synchronization pointscv_.wait(lock, predicate)— handles both missed notifications and spurious wakeupssignalAppStart()andsetup_eve()set their respective flags under lock before notifying