Skip to content

Commit ada0d61

Browse files
Fix race in ComWrappers test (#51153)
Since the finalizer thread runs async with the test, we need to atomically decrement the static instance counter.
1 parent 927b1c5 commit ada0d61

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/tests/Interop/COM/ComWrappers/Common.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class Test : ITest, ICustomQueryInterface
2121
{
2222
public static int InstanceCount = 0;
2323

24+
private int id;
2425
private int value = -1;
25-
public Test() { InstanceCount++; }
26-
~Test() { InstanceCount--; }
26+
public Test() { id = Interlocked.Increment(ref InstanceCount); }
27+
~Test() { Interlocked.Decrement(ref InstanceCount); id = -1; }
2728

2829
public void SetValue(int i) => this.value = i;
2930
public int GetValue() => this.value;

0 commit comments

Comments
 (0)