From be738c9d1c1612f5cb0a84227f5ced2726ae609e Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Tue, 17 May 2022 08:53:51 -0700 Subject: [PATCH] [lldb-vscode] Fix data race in lldb-vscode when running with ThreadSanitizer This patch fixes https://github.com/llvm/llvm-project/issues/54768. A ProgressEventReporter creates a dedicated thread that keeps checking whether there are new events that need to be sent to IDE as long as m_thread_should_exit is true. When the VSCode instance is destructed, it will set m_thread_should_exit to false, which caused a data race because at the same time its ProgressEventReporter is reading this value to determine whether it should quit. This fix simply uses mutex to ensure they cannot read and write this value at the same time. Committed on behalf of PRESIDENT810 Reviewed By: clayborg, wallace Differential Revision: https://reviews.llvm.org/D125073 --- lldb/tools/lldb-vscode/ProgressEvent.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-vscode/ProgressEvent.h b/lldb/tools/lldb-vscode/ProgressEvent.h index 627d723..7fa79ff 100644 --- a/lldb/tools/lldb-vscode/ProgressEvent.h +++ b/lldb/tools/lldb-vscode/ProgressEvent.h @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include #include #include #include @@ -149,7 +150,7 @@ private: std::queue m_unreported_start_events; /// Thread used to invoke \a ReportStartEvents periodically. std::thread m_thread; - bool m_thread_should_exit; + std::atomic m_thread_should_exit; /// Mutex that prevents running \a Push and \a ReportStartEvents /// simultaneously, as both read and modify the same underlying objects. std::mutex m_mutex; -- 2.7.4