Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 25e7be4

Browse files
Merge pull request #7162 from JosephTremoulet/VolatileTest
Add missing volatile annotation to test
2 parents a4bdd3b + f6b070c commit 25e7be4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/src/GC/Scenarios/FinalizeTimeout/FinalizeTimeout.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static int Main(string[] args)
1717
do
1818
{
1919
finalizableObject = new BlockingFinalizerOnShutdown();
20+
GC.KeepAlive(finalizableObject);
2021
} while (!BlockingFinalizerOnShutdown.finalizerCompletedOnce);
2122

2223
// Start a bunch of threads that allocate continuously, to increase the chance that when Main returns, one of the
@@ -42,12 +43,15 @@ private static void ThreadMain()
4243
{
4344
byte[] b;
4445
while (true)
46+
{
4547
b = new byte[1024];
48+
GC.KeepAlive(b);
49+
}
4650
}
4751

4852
private class BlockingFinalizerOnShutdown
4953
{
50-
public static bool finalizerCompletedOnce = false;
54+
public volatile static bool finalizerCompletedOnce = false;
5155
public bool isLastObject = false;
5256

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

7378
Console.WriteLine("Finalizer end");

0 commit comments

Comments
 (0)