[Lldb-commits] [lldb] [lldb][windows] fix a race condition in IO reader thread (PR #194422)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 27 10:46:39 PDT 2026
================
@@ -740,9 +740,39 @@ ProcessWindows::OnDebugException(bool first_chance,
return ExceptionResult::SendToApplication;
}
+ // Drain any in-flight process output before announcing the stop. The I/O
+ // reader thread and this debug-event thread run concurrently. Without
+ // synchronization the eBroadcastBitStateChanged(Stopped) event can reach
+ // the Debugger event thread before the preceding eBroadcastBitSTDOUT
+ // events.
+ auto drain_stdout = [this] {
+ if (!m_stdio_communication.ReadThreadIsRunning())
+ return;
+ m_stdio_communication.SynchronizeWithReadThread();
+ if (!m_pty || m_pty->GetMode() != PseudoConsole::Mode::ConPTY)
+ return;
+
+ HANDLE pipe = m_pty->GetSTDOUTHandle();
+ for (int consec_empty = 0; consec_empty < 3;) {
----------------
charles-zablit wrote:
I'm not a fan of this loop as it introduces timing in lldb. I think we can't escape it however, since the ConPTY API does not have any synchronization mechanism as far as I know.
https://github.com/llvm/llvm-project/pull/194422
More information about the lldb-commits
mailing list