Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / sgen-weakref-stress.cs
1 using System;
2 using System.Threading;
3
4 public class Tests
5 {
6         const int thread_count = 10;
7         const int weakrefs_per_thread = 5000;
8         const int crash_loops = 5;
9         public static void CrashRound () {
10                 var t = new Thread [thread_count];
11                 int fcount = 0;
12                 for (int i = 0; i < thread_count; ++i) {
13                         t [i] = new Thread (delegate () {
14                            for (int j = 0; j < weakrefs_per_thread; ++j) {
15                                new WeakReference (new object ());
16                            }
17                            Interlocked.Increment (ref fcount);
18                         });
19                 }
20
21                 for (int i = 0; i < thread_count; ++i)
22                         t [i].Start ();
23
24                 while (true) {
25                         if (fcount == thread_count)
26                                 break;
27                         GC.Collect ();
28                         Thread.Sleep (1);
29                 }
30         }
31         
32         public static void Main () {
33                 for (int i = 0; i < crash_loops; ++i) {
34                         Console.WriteLine ("{0}", i);
35                         CrashRound ();
36                 }
37         }
38 }