Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / sgen-domain-unload-2.cs
blobd63cd62d9eb4ab3a77cff750a629dc3d0bb25dda
1 using System;
2 using System.Threading;
4 /*
5 This test stresses what happens when root domain threads are allocating into the nursery
6 while a domain is cleaned up.
8 This is a regression test for a crash in the domain object cleaner code that did not
9 stop-the-world before walking the heap.
11 class Driver {
12 static void AllocStuff ()
14 var x = new object ();
15 for (int i = 0; i < 300; ++i)
16 x = new byte [i];
19 static void BackgroundNoise ()
21 while (true)
22 AllocStuff ();
25 static void Main () {
26 for (int i = 0; i < Math.Max (1, Environment.ProcessorCount / 2); ++i) {
27 // for (int i = 0; i < 4; ++i) {
28 var t = new Thread (BackgroundNoise);
29 t.IsBackground = true;
30 t.Start ();
33 int iterations = 0;
35 for (TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 120 : 5)); timeout.HaveTimeLeft;) {
36 var ad = AppDomain.CreateDomain ("domain_" + iterations);
37 ad.DoCallBack (new CrossAppDomainDelegate (AllocStuff));
38 AppDomain.Unload (ad);
40 Console.Write (".");
41 if ((++iterations) % 20 == 0) Console.WriteLine ();
43 Console.WriteLine ($"\ndone {iterations} iterations");