From 12e80789cc87264bc4d98d4bb9a02c4141b7b70a Mon Sep 17 00:00:00 2001 From: Peter Sollich Date: Wed, 18 May 2022 17:21:48 +0200 Subject: [PATCH] Add the repro case for github issue #68443 (https://github.com/dotnet/runtime/issues/68443) as a GC test case. --- src/tests/GC/Stress/Tests/DictionaryGrowth.cs | 44 +++++++++++++++++++ .../GC/Stress/Tests/DictionaryGrowth.csproj | 10 +++++ 2 files changed, 54 insertions(+) create mode 100644 src/tests/GC/Stress/Tests/DictionaryGrowth.cs create mode 100644 src/tests/GC/Stress/Tests/DictionaryGrowth.csproj diff --git a/src/tests/GC/Stress/Tests/DictionaryGrowth.cs b/src/tests/GC/Stress/Tests/DictionaryGrowth.cs new file mode 100644 index 00000000000000..6e8338a7544319 --- /dev/null +++ b/src/tests/GC/Stress/Tests/DictionaryGrowth.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// This test causes a lot of ephemeral and background GCs to happen +// It's a repro case for a race condition in background GC + +using System; +using System.Collections.Generic; +using System.Threading; + +internal class Program +{ + static void Run() + { + for (int iter = 0; iter < 1000_000; iter++) + { + var d = new Dictionary>(); + for (int i = 0; i < 10 * 1000; i++) + { + d[i.ToString()] = new ValueTuple(i, -1); + } + } + } + + static void Main(string[] args) + { + int startTick = System.Environment.TickCount; + const int threadCount = 4; + Thread[] ta = new Thread[threadCount]; + for (int i = 0; i < threadCount; i++) + { + ThreadStart ts = new ThreadStart(Run); + Thread t = new Thread(ts); + t.Start(); + ta[i] = t; + } + for (int i = 0; i < threadCount; i++) + { + ta[i].Join(); + } + double elapsed = 0.001*(System.Environment.TickCount - startTick); + Console.WriteLine("{0} seconds", elapsed); + } +} diff --git a/src/tests/GC/Stress/Tests/DictionaryGrowth.csproj b/src/tests/GC/Stress/Tests/DictionaryGrowth.csproj new file mode 100644 index 00000000000000..1bd35237646c71 --- /dev/null +++ b/src/tests/GC/Stress/Tests/DictionaryGrowth.csproj @@ -0,0 +1,10 @@ + + + Exe + true + BuildOnly + + + + +