Merge pull request #5390 from kumpera/fix_58637
[mono.git] / mono / tests / thread-stress.cs
1 using System;
2 using System.Threading;
3
4 class T {
5         static int loops = 20;
6         static int threads = 100;
7
8         static void worker () {
9                 /* a writeline happens to involve lots of code */
10                 Console.WriteLine ("Thread start " + Thread.CurrentThread.GetHashCode ());
11         }
12
13         static void doit () {
14                 Thread[] ta = new Thread [threads];
15                 for (int i = 0; i < threads; ++i) {
16                         ta [i] = new Thread (new ThreadStart (worker));
17                         ta [i].Start ();
18                 }
19                 for (int i = 0; i < threads; ++i) {
20                         ta [i].Join ();
21                 }
22         }
23         static void Main (string[] args) {
24                 if (args.Length > 0)
25                         loops = int.Parse (args [0]);
26                 if (args.Length > 1)
27                         threads = int.Parse (args [1]);
28                 for (int i = 0; i < loops; ++i) {
29                         doit ();
30                 }
31         }
32 }
33