JDevlieghere created this revision. JDevlieghere added reviewers: labath, mib. JDevlieghere requested review of this revision.
We got a few crash reports that showed LLDB initializing Python on two separate threads. Make `g_initialized` atomic to prevent that from happening. https://reviews.llvm.org/D117601 Files: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -85,7 +85,7 @@ return static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); } -static bool g_initialized = false; +static std::atomic<bool> g_initialized(false); namespace { @@ -3194,11 +3194,12 @@ #endif void ScriptInterpreterPythonImpl::InitializePrivate() { - if (g_initialized) + bool initialized = false; + const bool exchanged = + g_initialized.compare_exchange_strong(initialized, true); + if (!exchanged) return; - g_initialized = true; - LLDB_SCOPED_TIMER(); // RAII-based initialization which correctly handles multiple-initialization,
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -85,7 +85,7 @@ return static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); } -static bool g_initialized = false; +static std::atomic<bool> g_initialized(false); namespace { @@ -3194,11 +3194,12 @@ #endif void ScriptInterpreterPythonImpl::InitializePrivate() { - if (g_initialized) + bool initialized = false; + const bool exchanged = + g_initialized.compare_exchange_strong(initialized, true); + if (!exchanged) return; - g_initialized = true; - LLDB_SCOPED_TIMER(); // RAII-based initialization which correctly handles multiple-initialization,
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits