From 4ad43957db9c8fdd904fb0cc563b8478b8a8a600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 8 Dec 2009 19:01:06 +0000 Subject: [PATCH] Backported r4826 "Fixed race condition that was causing unit tests to fail" to 3.1 git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5309 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Debugger.Core/Project/Src/Control/NDebugger.cs | 12 +++++++++--- .../Project/Src/Internal/ManagedCallbackSwitch.cs | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs index 0a3c42068c..82c6311feb 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs @@ -157,12 +157,18 @@ namespace Debugger process.Start(); } + internal object ProcessIsBeingCreatedLock = new object(); + public Process Start(string filename, string workingDirectory, string arguments) { InitDebugger(GetProgramVersion(filename)); - Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); - AddProcess(process); - return process; + lock(ProcessIsBeingCreatedLock) { + Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); + // Expose a race conditon + System.Threading.Thread.Sleep(0); + AddProcess(process); + return process; + } } public Process Attach(System.Diagnostics.Process existingProcess) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs index e181b60466..e1aaebbd77 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs @@ -73,7 +73,11 @@ namespace Debugger public ManagedCallback GetProcessCallbackInterface(string name, ICorDebugProcess pProcess) { - Process process = debugger.GetProcess(pProcess); + Process process; + // We have to wait until the created process is added into the collection + lock(debugger.ProcessIsBeingCreatedLock) { + process = debugger.GetProcess(pProcess); + } // Make *really* sure the process is not dead if (process == null) { debugger.TraceMessage("Ignoring callback \"" + name + "\": Process not found");