[lldb/Target] Avoid race between Communication::Disconnect calls.
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 22 Apr 2020 23:51:56 +0000 (16:51 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 22 Apr 2020 23:56:42 +0000 (16:56 -0700)
Avoid a race between the Disconnect call in `Communication::ReadThread`
and the one in `Process::ShouldBroadcastEvent` by reordering the calls
to Disconnect and StopReadThread in `Process::ShouldBroadcastEvent`.

In D77295 Pavel suggested that that might explain the broken pipe I was
seeing. Indeed, changing the order resolved the issue.

lldb/source/Target/Process.cpp

index 7797a4c..45dcfc4 100644 (file)
@@ -3386,8 +3386,8 @@ bool Process::ShouldBroadcastEvent(Event *event_ptr) {
   case eStateExited:
   case eStateUnloaded:
     m_stdio_communication.SynchronizeWithReadThread();
-    m_stdio_communication.Disconnect();
     m_stdio_communication.StopReadThread();
+    m_stdio_communication.Disconnect();
     m_stdin_forward = false;
 
     LLVM_FALLTHROUGH;