Author: Walter Erquinigo Date: 2022-05-17T09:11:45-07:00 New Revision: be738c9d1c1612f5cb0a84227f5ced2726ae609e
URL: https://github.com/llvm/llvm-project/commit/be738c9d1c1612f5cb0a84227f5ced2726ae609e DIFF: https://github.com/llvm/llvm-project/commit/be738c9d1c1612f5cb0a84227f5ced2726ae609e.diff LOG: [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 Added: Modified: lldb/tools/lldb-vscode/ProgressEvent.h Removed: ################################################################################ diff --git a/lldb/tools/lldb-vscode/ProgressEvent.h b/lldb/tools/lldb-vscode/ProgressEvent.h index 627d723e5c263..7fa79ffca0fc0 100644 --- a/lldb/tools/lldb-vscode/ProgressEvent.h +++ b/lldb/tools/lldb-vscode/ProgressEvent.h @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include <atomic> #include <mutex> #include <queue> #include <thread> @@ -149,7 +150,7 @@ class ProgressEventReporter { std::queue<ProgressEventManagerSP> m_unreported_start_events; /// Thread used to invoke \a ReportStartEvents periodically. std::thread m_thread; - bool m_thread_should_exit; + std::atomic<bool> 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; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits