Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/src/GC/Scenarios/FinalizeTimeout/FinalizeTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static int Main(string[] args)
do
{
finalizableObject = new BlockingFinalizerOnShutdown();
GC.KeepAlive(finalizableObject);
} while (!BlockingFinalizerOnShutdown.finalizerCompletedOnce);

// Start a bunch of threads that allocate continuously, to increase the chance that when Main returns, one of the
Expand All @@ -42,12 +43,15 @@ private static void ThreadMain()
{
byte[] b;
while (true)
{
b = new byte[1024];
GC.KeepAlive(b);
}
}

private class BlockingFinalizerOnShutdown
{
public static bool finalizerCompletedOnce = false;
public volatile static bool finalizerCompletedOnce = false;
public bool isLastObject = false;

~BlockingFinalizerOnShutdown()
Expand All @@ -68,6 +72,7 @@ private class BlockingFinalizerOnShutdown
do
{
o = new object();
GC.KeepAlive(o);
} while ((++i & 0xff) != 0 || (elapsed = DateTime.Now - start) < timeout);

Console.WriteLine("Finalizer end");
Expand Down