From b1d42b5b72fdbc70b8541756471357d6ba79c32a Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Mon, 12 Apr 2021 17:02:40 -0700 Subject: [PATCH] Fix race in ComWrappers test Since the finalizer thread runs async with the test, we need to atomically decrement the static instance counter. --- src/tests/Interop/COM/ComWrappers/Common.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tests/Interop/COM/ComWrappers/Common.cs b/src/tests/Interop/COM/ComWrappers/Common.cs index 5d1994131e7a76..4aa98b76e9031c 100644 --- a/src/tests/Interop/COM/ComWrappers/Common.cs +++ b/src/tests/Interop/COM/ComWrappers/Common.cs @@ -21,9 +21,10 @@ class Test : ITest, ICustomQueryInterface { public static int InstanceCount = 0; + private int id; private int value = -1; - public Test() { InstanceCount++; } - ~Test() { InstanceCount--; } + public Test() { id = Interlocked.Increment(ref InstanceCount); } + ~Test() { Interlocked.Decrement(ref InstanceCount); id = -1; } public void SetValue(int i) => this.value = i; public int GetValue() => this.value;