[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 18 13:34:37 PST 2022


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117601.400970.patch
Type: text/x-patch
Size: 901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220118/7f47a126/attachment.bin>


More information about the lldb-commits mailing list