Skip to content

Commit

Permalink
fix infinite loop in foregroundgc test (#106006)
Browse files Browse the repository at this point in the history
* fix infinite loop for foregroundgc

* Update src/tests/GC/Features/BackgroundGC/foregroundgc.cs

Co-authored-by: Mark Plesko <[email protected]>

* remove redundant volatile and clean the code

---------

Co-authored-by: Mukund Raghav Sharma (Moko) <[email protected]>
Co-authored-by: Mark Plesko <[email protected]>
  • Loading branch information
3 people authored Aug 11, 2024
1 parent dedd372 commit fb8ae3e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tests/GC/Features/BackgroundGC/foregroundgc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -70,7 +71,11 @@ static int Main(string[] args)
}
}

done = true;
lock(_lock)
{
done = true;
}

t.Join();
Console.WriteLine("List count=" + List1.Count);

Expand All @@ -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];
}
Expand Down

0 comments on commit fb8ae3e

Please sign in to comment.