3 using System
.Threading
;
6 private void Thread_func() {
7 Console
.WriteLine("In a thread!");
9 Thread thr
=Thread
.CurrentThread
;
11 Console
.WriteLine("Locking thr for 1.5s");
13 Console
.WriteLine("Locked");
15 Console
.WriteLine("Slept for 2s");
19 Console
.WriteLine("Waiting for signal");
21 Console
.WriteLine("Waiting...");
23 Console
.WriteLine("Thread signalled!");
26 Console
.WriteLine("Sleeping for 2s");
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
));
38 Console
.WriteLine("Trying to enter lock");
39 if(Monitor
.TryEnter(thr
, 1000)==true) {
40 Console
.WriteLine("Returned lock");
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
51 // SynchronizationLockException... (like it
60 Console
.WriteLine("Signalled thread");