diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -378,11 +378,18 @@ void LeaveSession(); - uint32_t IsExecutingPython() const { return m_lock_count > 0; } + uint32_t IsExecutingPython() { + std::lock_guard guard(m_mutex); + return m_lock_count > 0; + } - uint32_t IncrementLockCount() { return ++m_lock_count; } + uint32_t IncrementLockCount() { + std::lock_guard guard(m_mutex); + return ++m_lock_count; + } uint32_t DecrementLockCount() { + std::lock_guard guard(m_mutex); if (m_lock_count > 0) --m_lock_count; return m_lock_count; @@ -422,6 +429,7 @@ bool m_pty_secondary_is_open; bool m_valid_session; uint32_t m_lock_count; + std::mutex m_mutex; PyThreadState *m_command_thread_state; }; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2467,6 +2467,7 @@ } void Process::LoadOperatingSystemPlugin(bool flush) { + std::lock_guard guard(m_thread_mutex); if (flush) m_thread_list.Clear(); m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));