diff --git a/src/tests/GC/Features/BackgroundGC/foregroundgc.cs b/src/tests/GC/Features/BackgroundGC/foregroundgc.cs index ad725a2d68308..579d26f8e1f8f 100644 --- a/src/tests/GC/Features/BackgroundGC/foregroundgc.cs +++ b/src/tests/GC/Features/BackgroundGC/foregroundgc.cs @@ -12,6 +12,7 @@ namespace ForegroundGC class ForegroundGC { static bool done = false; + readonly static object _lock = new object(); static long maxAlloc = 1024 * 1024 * 1024; //1GB max size static int size = 30; static int Main(string[] args) @@ -70,7 +71,11 @@ static int Main(string[] args) } } - done = true; + lock(_lock) + { + done = true; + } + t.Join(); Console.WriteLine("List count=" + List1.Count); @@ -82,8 +87,9 @@ static int Main(string[] args) static void AllocateTemp() { - while (!done) + while (true) { + lock(_lock) { if (done) { break; } } byte[] b = new byte[30]; byte[] b2 = new byte[100]; }