Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / namedmutex-destroy-race.cs
1
2 /* test for https://bugzilla.xamarin.com/show_bug.cgi?id=41914 */
3
4 using System;
5 using System.Threading;
6
7 namespace Crasher
8 {
9         class Program
10         {
11                 public static void Main (string[] args)
12                 {
13                         Thread[] threads = new Thread[100];
14
15                         DateTime start = DateTime.Now;
16
17                         for (int i = 0; i < threads.Length; ++i) {
18                                 threads [i] = new Thread (() => {
19                                         var rnd = new Random();
20                                         do {
21                                                 using (var mutex = new Mutex(false, "Global\\TEST")) {
22                                                         var owner = false;
23                                                         try {
24                                                                 owner = mutex.WaitOne(TimeSpan.FromMinutes(1));
25                                                         } finally {
26                                                                 if (owner)
27                                                                         mutex.ReleaseMutex();
28                                                         }
29                                                 }
30                                                 Thread.Sleep(rnd.Next(100, 1000));
31                                         } while ((DateTime.Now - start) < TimeSpan.FromSeconds (10));
32                                 });
33                         }
34
35                         for (int i = 0; i < threads.Length; ++i)
36                                 threads [i].Start ();
37
38                         for (int i = 0; i < threads.Length; ++i)
39                                 threads [i].Join ();
40                 }
41
42                 private static void Crasher(){
43                 }
44         }
45 }