[runtime] Require C# namespace to be quoted.
[mono-project.git] / mono / tests / thread3.cs
blob3b59df49814071b0b4ca1fd14a2149548c7fea6b
2 using System;
3 using System.Threading;
5 public class Test {
6 private void Thread_func() {
7 Console.WriteLine("In a thread!");
9 Thread thr=Thread.CurrentThread;
11 Console.WriteLine("Locking thr for 1.5s");
12 lock(thr) {
13 Console.WriteLine("Locked");
14 Thread.Sleep(2000);
15 Console.WriteLine("Slept for 2s");
16 Thread.Sleep(15000);
19 Console.WriteLine("Waiting for signal");
20 lock(thr) {
21 Console.WriteLine("Waiting...");
22 Monitor.Wait(thr);
23 Console.WriteLine("Thread signalled!");
26 Console.WriteLine("Sleeping for 2s");
27 Thread.Sleep(2000);
29 Console.WriteLine("Leaving thread");
32 public static int Main () {
33 Console.WriteLine ("Hello, World!");
34 Thread thr=new Thread(new ThreadStart(new Test().Thread_func));
35 thr.Start();
36 Thread.Sleep(1000);
38 Console.WriteLine("Trying to enter lock");
39 if(Monitor.TryEnter(thr, 1000)==true) {
40 Console.WriteLine("Returned lock");
41 Monitor.Exit(thr);
42 } else {
43 Console.WriteLine("Didn't get lock");
44 // .net seems to leave thr locked here !!!!
46 // This test deadlocks on .net with the thread
47 // trying to lock(thr) between the two
48 // WriteLine()s Monitor.Exit(thr); here and it
49 // magically works :) Of course, then mint
50 // throws a
51 // SynchronizationLockException... (like it
52 // should)
53 //Monitor.Exit(thr);
56 Thread.Sleep(20000);
58 lock(thr) {
59 Monitor.Pulse(thr);
60 Console.WriteLine("Signalled thread");
63 thr.Join();
65 return 0;