You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cpp: move DFA write locks from the ATN onto the DFA
DFA construction (addDFAState's state-set dedup and DFAState::setEdge) was
serialized by ATN::_stateMutex / ATN::_edgeMutex. But each ParserInterpreter /
LexerInterpreter owns its own decisionToDFA, so concurrent interpreters over a
shared (read-only) ATN serialized on a single per-ATN lock for DFA writes they
do not share — concurrency became a net loss (measured ~0.6x of serial on 4
threads).
Move those two write locks onto the DFA itself (dfa::DFA::stateMutex/edgeMutex,
heap-allocated so DFA stays movable) and lock the owning DFA in the simulators.
ATN::_mutex (lazy nextTokens cache) is unchanged; edge reads stay lock-free.
Independent DFAs now use independent locks (concurrent interpreters scale ~2.1x
on 4 threads); a DFA shared across threads (generated recognizers' static
decisionToDFA) still serializes its own writers, now at per-decision rather than
per-ATN granularity. Same locking discipline, finer scope.
Verified with a ThreadSanitizer build of the runtime + an 8-thread concurrent
parse harness over a shared ATN: no data races.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Christopher Barber <analog.cbarber@gmail.com>
0 commit comments