[Reproducers] Fix data race found by tsan
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 14 Mar 2019 17:19:34 +0000 (17:19 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 14 Mar 2019 17:19:34 +0000 (17:19 +0000)
This fixes a data race uncovered by tsan during destruction of the
GDBRemoteReplay server. The solution is to lock the thread state mutex
when receiving packets.

llvm-svn: 356168

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp

index 50a53b4..26784ec 100644 (file)
@@ -55,6 +55,8 @@ GDBRemoteCommunicationReplayServer::~GDBRemoteCommunicationReplayServer() {
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
     Timeout<std::micro> timeout, Status &error, bool &interrupt, bool &quit) {
+  std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
+
   StringExtractorGDBRemote packet;
   PacketResult packet_result = WaitForPacketNoLock(packet, timeout, false);