[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU]Monitor weirdness
From: |
Russell Stuart |
Subject: |
Re: [DotGNU]Monitor weirdness |
Date: |
05 May 2004 16:35:22 +1000 |
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?