RE: Monitor weirdness
"Thong (Tum) Nguyen" <tum-x2aT3/[email protected]>
| Newsgroups | gmane.comp.gnu.dotgnu.developer |
|---|---|
| Message-ID | <[email protected]> |
It doesn't do it if you've got the debugger attached (ahhh!). Try running it without the debugger. > -----Original Message----- > From: Russell Stuart [mailto:russell-M7Clnf/[email protected]] > Sent: Wednesday, 5 May 2004 6:35 p.m. > To: Thong (Tum) Nguyen > Cc: [email protected]; Russell Fitchett > Subject: Re: [DotGNU]Monitor weirdness > > On Wed, 2004-05-05 at 15:49, Thong (Tum) Nguyen wrote: > > Check this code out: > > > > using System; > > using System.Threading; > > > > public class Test > > { > > Thread thread1, thread2; > > > > public void Run1() > > { > > Thread.Sleep(1000); > > > > lock (this) > > { > > Monitor.Pulse(this); > > thread2.Interrupt(); > > > > for (;;) > > { > > Console.WriteLine("Thread 1"); > > } > > } > > } > > > > public void Run2() > > { > > lock (this) > > { > > try > > { > > Monitor.Wait(this); > > } > > catch (ThreadInterruptedException) > > { > > Console.WriteLine("2 Interrupted"); > > } > > > > for (;;) > > { > > Console.WriteLine("Thread 2"); > > } > > } > > } > > > > public void Go() > > { > > thread1 = new Thread(new ThreadStart(Run1)); > > thread2 = new Thread(new ThreadStart(Run2)); > > > > thread1.Start(); > > thread2.Start(); > > } > > > > public static void Main() > > { > > new Test().Go(); > > } > > } > > > > > > On MS.NET you get a "Thread 1" and "Thread 2" printing out (alternating) > > which makes it looks like both synchronization blocks are running at > once > > (which they are!). Ouch. > > I compiled it under VS 2003 and ran it. Only "Thread 1" was printed > out. Thread 2 did not exit the Wait() call. I replaced the the > Interrupt() with Abort(), and got the same result. > > Under dotgnu 0.6.4 and the current CVS it ran identically. > > Russell - did you run it on a multi CPU machine? > > _______________________________________________ > Developers mailing list > [email protected] > http://dotgnu.org/mailman/listinfo/developers