[Mono-bugs] [Bug 317647] Thread.Interrupt not working
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Aug 12 03:00:28 EDT 2009
http://bugzilla.novell.com/show_bug.cgi?id=317647
User andrew at it.swin.edu.au added comment
http://bugzilla.novell.com/show_bug.cgi?id=317647#c4
Andrew Cain <andrew at it.swin.edu.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrew at it.swin.edu.au
Platform|Other |i386
Version|1.1 |2.4.x
Target Milestone|--- |2.4.x
OS/Version|Other |Mac OS X 10.5
--- Comment #4 from Andrew Cain <andrew at it.swin.edu.au> 2009-08-12 01:00:24 MDT ---
Also see 320004 - interrupt seems to be working as expected on MacOS, but does
not work correctly when embedded within finally blocks. Changing the sample
code to the following demonstrates the incorrect behaviour (placed T2 code in a
finally block). This produces an infinite loop in MS.net but terminates in
Mono.
using System;
using System.Threading;
namespace MonitorSynchro
{
class MonitorSample
{
Thread t1;
Thread t2;
object myLock = new object();
public void ThreadProc1()
{
Console.WriteLine("T1 getting lock...");
lock (myLock)
{
Console.WriteLine("T1 got the lock.");
Console.WriteLine("T1 sleeping for 10 sec...");
Thread.Sleep(1000);
Console.WriteLine("T1 woke up. Pulse and wait now...");
Monitor.Pulse(myLock);
Monitor.Wait(myLock);
Console.WriteLine("T1 woke up. Stopping T2 in 10 sec...");
Thread.Sleep(1000);
Console.WriteLine("T1 stopping T2 now.");
t2.Interrupt();
}
Console.WriteLine("T1 released lock and waiting for T2.");
t2.Join();
Console.WriteLine("T1 leaving. Bye!");
}
public void ThreadProc2()
{
bool working = true;
while (working)
{
try
{ }
finally
{
try
{
Console.WriteLine("T2 getting lock...");
lock (myLock)
{
Console.WriteLine("T2 got the lock.");
Console.WriteLine("T2 sleeping for 5 sec...");
Thread.Sleep(500);
Console.WriteLine("T2 woke up. Pulse and sleep 1
sec now...");
Monitor.Pulse(myLock);
Thread.Sleep(100);
}
Console.WriteLine("T2 released lock.");
}
catch (ThreadInterruptedException)
{
Console.WriteLine("T2 being asked to quit.");
working = false;
}
}
}
Console.WriteLine("T2 leaving. Bye!");
}
public MonitorSample()
{
t1 = new Thread(new ThreadStart(ThreadProc1));
t2 = new Thread(new ThreadStart(ThreadProc2));
t2.Start();
t1.Start();
t1.Join();
}
static void Main(string[] args)
{
new MonitorSample();
return;
}
}
}
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list