[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / monitor-stress.cs
blobcdda429a874958fe234b58b02230d6d081146e2c
1 using System;
2 using System.Threading;
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 ();
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;
24 // again, after a GC
25 GC.Collect ();
26 for (int i = 0; i < count; ++i) {
27 lock (array [i]) {
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]) {
42 static void worker () {
43 for (int i = 0; i < loops; ++i)
44 stress_loop ();
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 ();
57 /* for good measure */
58 worker ();