Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / monitor-wait-abort.cs
1 using System;
2 using System.Threading;
3
4 public class Program {
5         const int num_threads = 10;
6         public static Barrier barrier = new Barrier (num_threads + 1);
7
8         public static void ThreadFunc ()
9         {
10                 object lock_obj = new object ();
11                 lock (lock_obj) {
12                         try {
13                                 barrier.SignalAndWait ();
14                                 Monitor.Wait (lock_obj);
15                         } catch (ThreadAbortException) {
16                                 Thread.ResetAbort ();
17                         }
18                 }
19         }
20
21         public static void Main (string[] args)
22         {
23                 Thread[] tarray = new Thread [num_threads];
24
25                 for (int i = 0; i < num_threads; i++) {
26                         tarray [i] = new Thread (new ThreadStart (ThreadFunc));
27                         tarray [i].Start ();
28                 }
29
30                 barrier.SignalAndWait ();
31
32                 for (int i = 0; i < num_threads; i++)
33                         tarray [i].Abort ();
34
35                 for (int i = 0; i < num_threads; i++)
36                         tarray [i].Join ();
37         }
38 }