[System] Tweak socket test
[mono-project.git] / mono / tests / namedmutex-destroy-race.cs
blobe34508696b9f9dd45356b934fd3f2c0c0cab793a
2 /* test for https://bugzilla.xamarin.com/show_bug.cgi?id=41914 */
4 using System;
5 using System.Threading;
7 namespace Crasher
9 class Program
11 public static void Main (string[] args)
13 Thread[] threads = new Thread[100];
15 DateTime start = DateTime.Now;
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();
30 Thread.Sleep(rnd.Next(100, 1000));
31 } while ((DateTime.Now - start) < TimeSpan.FromSeconds (10));
32 });
35 for (int i = 0; i < threads.Length; ++i)
36 threads [i].Start ();
38 for (int i = 0; i < threads.Length; ++i)
39 threads [i].Join ();
42 private static void Crasher(){