[interp] disable assemblyresolve_event6.exe
[mono.git] / mono / tests / monitor-stress.cs
1 using System;
2 using System.Threading;
3
4 class T {
5         static int count = 20000;
6         static int loops = 80;
7         static int threads = 10;
8         static object global_obj;
9         static void stress_loop () {
10                 object obj = new object ();
11                 lock (obj) {
12                         object [] array = new object [count];
13                         for (int i = 0; i < count; ++i) {
14                                 array [i] = new object ();
15                         }
16                         for (int i = 0; i < count; ++i) {
17                                 lock (array [i]) {
18                                         global_obj = new String ('x', 32);
19                                         if ((i % 12) == 0) {
20                                                 array [i] = global_obj;
21                                         }
22                                 }
23                         }
24                         // again, after a GC
25                         GC.Collect ();
26                         for (int i = 0; i < count; ++i) {
27                                 lock (array [i]) {
28                                 }
29                         }
30                         // two times, with feeling
31                         for (int i = 0; i < count; ++i) {
32                                 lock (array [i]) {
33                                         for (int j = 0; i < count; ++i) {
34                                                 lock (array [j]) {
35                                                 }
36                                         }
37                                 }
38                         }
39                 }
40         }
41
42         static void worker () {
43                 for (int i = 0; i < loops; ++i)
44                         stress_loop ();
45         }
46         static void Main (string[] args) {
47                 if (args.Length > 0)
48                         loops = int.Parse (args [0]);
49                 if (args.Length > 1)
50                         count = int.Parse (args [1]);
51                 if (args.Length > 1)
52                         threads = int.Parse (args [2]);
53                 for (int i = 0; i < threads; ++i) {
54                         Thread t = new Thread (new ThreadStart (worker));
55                         t.Start ();
56                 }
57                 /* for good measure */
58                 worker ();
59         }
60 }