[interp] disable some tests that fail on CI only
[mono.git] / mono / tests / mutexes.cs
1 /////////////////////////////////// Test Overview ////////////////////////////////\r
2 // \r
3 // Two threads are started from Main, which allocates 10 static mutexes.\r
4 // The first thread locks each mutex in turn, with a delay of 2000ms between\r
5 // locks.\r
6 // The second thread recursively locks mutex no. 5 10 times, blocking the\r
7 // progress of the first thread as this second thread has a delay of 4500ms\r
8 // between each lock.When the second thread has called ReleaseMutex on the mutex 10\r
9 // times it terminates and the first thread can carry on its cycle of locking and\r
10 // releasing mutexes until it exits.\r
11 //\r
12 /////////////////////////////////////////////////////////////////////////////////\r
13 \r
14 \r
15 using System;\r
16 using System.Threading;\r
17 \r
18 class MutexTest\r
19 {  \r
20         public static Mutex[] m;\r
21 \r
22     // Code for first thread\r
23         public static void ThreadMethod_A()\r
24     {   \r
25         Console.WriteLine("[Thread A] - Started.....");\r
26         \r
27         for (int i=0;i<10;i++)\r
28                 {\r
29                 Console.WriteLine("[Thread A] - Trying to lock mutex "+i+"...");\r
30                 m[i].WaitOne();\r
31                 Console.WriteLine("[Thread A] - m["+i+"] Locked!");     \r
32                 Console.WriteLine("[Thread A] - Now using  mutex ["+i+"]");     \r
33                 Thread.Sleep(2000);\r
34                 m[i].ReleaseMutex();\r
35                 Console.WriteLine("[Thread A] - Unlocked the mutex ["+i+"]");\r
36                 }\r
37         \r
38         Console.WriteLine("[Thread A] - exiting.....");\r
39     }\r
40     \r
41     // Code for second thread\r
42     public static void ThreadMethod_B()\r
43     {\r
44         Console.WriteLine("[Thread B] - Started.....");\r
45 \r
46         for (int h=0;h<10;h++)\r
47                 {\r
48                 int i=5;                \r
49                 Console.WriteLine("[Thread B] - Trying to lock mutex "+i+" for "+h+" time...");\r
50                 m[i].WaitOne();\r
51                 Console.WriteLine("[Thread B] - m["+i+"] Locked recursively ["+h+"] times!");           \r
52                 Thread.Sleep(4500);\r
53                 }\r
54         for (int h=0;h<10;h++)\r
55                 {\r
56                 int i=5;                \r
57                 m[i].ReleaseMutex();\r
58                 Console.WriteLine("[Thread B] - Unlocked the mutex ["+i+"] for ["+h+"] times");\r
59                 }\r
60 \r
61         Console.WriteLine("[Thread B] - Finished.....");\r
62     }\r
63     \r
64     \r
65     public static void Main()\r
66     {           \r
67         m = new Mutex[10];\r
68         for (int i = 0 ; i<10 ; i++ ) \r
69                 m[i] = new Mutex();\r
70         \r
71         // Create the first thread\r
72         Console.WriteLine("[  Main  ] - Creating first thread..");\r
73         ThreadStart Thread_1 = new ThreadStart(ThreadMethod_A);\r
74         \r
75         // Create the second thread\r
76         Console.WriteLine("[  Main  ] - Creating second thread..");\r
77         ThreadStart Thread_2 = new ThreadStart(ThreadMethod_B);\r
78 \r
79         Thread A = new Thread(Thread_1);\r
80         Thread B = new Thread(Thread_2);\r
81         A.Start();\r
82         B.Start();\r
83         \r
84         Thread.Sleep(500);\r
85         Console.WriteLine("[  Main  ] - Test Ended");\r
86     }\r
87 }\r