<rdar://problem/11751427> Fixing an issue where multiple threads could concurrently try and initialize Python and cause crashes

llvm-svn: 160008
This commit is contained in:
Enrico Granata 2012-07-10 18:23:48 +00:00
parent 3ee9a4c29e
commit a29bdad954
1 changed files with 10 additions and 0 deletions

View File

@ -2390,6 +2390,16 @@ CommandInterpreter::HandleCommandsFromFile (FileSpec &cmd_file,
ScriptInterpreter *
CommandInterpreter::GetScriptInterpreter ()
{
// <rdar://problem/11751427>
// we need to protect the initialization of the script interpreter
// otherwise we could end up with two threads both trying to create
// their instance of it, and for some languages (e.g. Python)
// this is a bulletproof recipe for disaster!
// this needs to be a function-level static because multiple Debugger instances living in the same process
// still need to be isolated and not try to initialize Python concurrently
static Mutex *interpreter_mutex = new Mutex(Mutex::eMutexTypeRecursive);
Mutex::Locker interpreter_lock(*interpreter_mutex);
if (m_script_interpreter_ap.get() != NULL)
return m_script_interpreter_ap.get();