[Mono-bugs] [Bug 74525][Blo] New - Thread.Interrupt does not seem to work properly

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 8 Apr 2005 13:23:03 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by christiano@croesus.com.

http://bugzilla.ximian.com/show_bug.cgi?id=74525

--- shadow/74525	2005-04-08 13:23:03.000000000 -0400
+++ shadow/74525.tmp.858	2005-04-08 13:23:03.000000000 -0400
@@ -0,0 +1,133 @@
+Bug#: 74525
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Fedora Core 3
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Blocker
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: christiano@croesus.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Thread.Interrupt does not seem to work properly
+
+Description of Problem:
+Thread.Interrupt does not seem to work properly. Using Thread.Abort() is 
+not a viable solution here.
+
+
+Steps to reproduce the problem:
+Run the sample code provided.
+<- Code sample START ->
+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(10000);
+				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(10000);
+				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
+				{
+					Console.WriteLine("T2 getting 
+lock...");
+					lock(myLock)
+					{
+						Console.WriteLine("T2 got 
+the lock.");
+						Console.WriteLine("T2 
+sleeping for 5 sec...");
+						Thread.Sleep(5000);
+						Console.WriteLine("T2 
+woke up. Pulse and sleep 1 sec now...");
+						Monitor.Pulse(myLock);
+						Thread.Sleep(1000);
+					}
+					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));
+
+			t1.Start();
+			t2.Start();
+
+			t1.Join();
+		}
+
+		static void Main(string[] args)
+		{
+			new MonitorSample();
+			return;
+		}
+	}
+}
+<- Code sample END ->
+
+Actual Results:
+Infinite loop for thread T2.
+
+Expected Results:
+Thread T2 would stop, followed by thread T1. The expected behavior is 
+correct under .NET.
+
+How often does this happen? 
+Always.
+
+Additional Information:
+Test ran and failed on a Dual Xeon machine with Fedora Core 3 (mono 
+1.1.5).
+Test also ran and failed on a Quad Xeon machine with RH9 (mono 1.1.4).
+Test also ran and failed on a single P3 machine with Windows XP (mono 
+1.1.4)