Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / bug-59281.cs
1 using System;
2 using System.Threading;
3
4 class Driver
5 {
6
7         static readonly Mutex[] mutexes = new Mutex[2];
8
9         public static void Main(string[] args)
10         {
11                 for (int i = 0; i < mutexes.Length; i++) {
12                         mutexes [i] = new Mutex();
13                 }
14
15                 Thread thread1 = new Thread(() => {
16                         for (int i = 0; i < 1; i++) {
17                                 int idx = -1;
18                                 try {
19                                         idx = WaitHandle.WaitAny (mutexes);
20                                         Console.WriteLine($"Thread 1 iter: {i} with mutex: {idx}");
21                                 } finally {
22                                         if (idx != -1)
23                                                 mutexes [idx].ReleaseMutex();
24                                 }
25                         }
26
27                         Console.WriteLine("Thread 1 ended");
28                 });
29
30                 thread1.Start();
31                 thread1.Join();
32
33                 Thread thread2 = new Thread(() => {
34                         for (int i = 0; i < 1000; i++) {
35                                 int idx = -1;
36                                 try {
37                                         idx = WaitHandle.WaitAny (mutexes);
38                                         Console.WriteLine($"Thread 2 iter: {i} with mutex: {idx}");
39                                 } finally {
40                                         if (idx != -1)
41                                                 mutexes [idx].ReleaseMutex();
42                                 }
43                         }
44
45                         Console.WriteLine("Thread 2 ended");
46                 });
47
48                 thread2.Start();
49                 thread2.Join();
50         }
51 }