[Mono-bugs] [Bug 59244][Wis] New - crash with mutex

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 28 May 2004 08:56:36 -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 hannibalbundie@hotmail.com.

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

--- shadow/59244	2004-05-28 08:56:36.000000000 -0400
+++ shadow/59244.tmp.11774	2004-05-28 08:56:36.000000000 -0400
@@ -0,0 +1,170 @@
+Bug#: 59244
+Product: Mono: Runtime
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: hannibalbundie@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: crash with mutex
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+The bug appears with a repetitive use of the mutex class. It causes a crash
+on mono although the test program works perfectly on Microsoft .NET.
+The bug seems to be due to a blocking on 'mutex.WaitOne();'. Nevertheless,
+the useless variable 'error' may have a role in this crash because without
+it, the message "GC Warning: Out of Memory!  Returning NIL!" is never shown.
+
+
+Steps to reproduce the problem:
+1. save this test program as test.cs :
+
+using System;
+using System.Threading;
+
+// This test almost always crash and no error is thrown.
+// Nevertheless, a message often appears : "GC Warning: Out of Memory! 
+Returning NIL!".
+// This message could be a consequence of the useless variable 'error' in
+the ProtectedRessource class.
+// The crash seems to be due to the mutex.WaitOne() in the
+ProtectedRessource constructor.
+
+namespace Test
+{
+	class Test {
+
+		private ThreadStart initialThreadStart          = null;
+		private Thread initialThread                    = null;
+
+		private static bool running  = false;
+
+		[STAThread]
+		static void Main(string[] args) {
+			Test test = new Test();
+
+			for (int i = 0 ; i < 5 ; i++)	//
+			{				// We start and stop a thread
+				test.StartClient();	// which uses a protecteed ressource
+				test.StopClient();	//
+			}				//
+
+			test.Quit();
+		}
+
+
+		private void StartClient() {
+			if (ClientStarting() ) Console.WriteLine("New client started");
+		}
+
+		private void StopClient() {
+			if(ClientStoping()) Console.WriteLine("Client stoped");
+			else Console.WriteLine("An error occured while stoping client");
+		}
+
+		private void Quit() {
+			Console.WriteLine("Bye. (press return)");
+			Console.ReadLine();
+			Environment.Exit(0);
+		}
+
+
+		private bool ClientStarting() {
+			bool ret = false;
+
+			try {
+				running = true;
+				initialThreadStart = new ThreadStart(this.RunClient2);
+				initialThread      = new Thread(initialThreadStart);
+				initialThread.Name = "Client_initial_Thread";
+				initialThread.Start();
+				ret = true;
+
+			} catch (System.SystemException exp) {
+				Console.WriteLine("Impossible to start client now");
+			}
+
+			return ret;
+		}
+
+		private bool ClientStoping() {
+			bool ret = false;
+
+			try {
+				running = false;
+				if(initialThread != null) this.initialThread.Abort();
+				this.initialThread = null;
+				ret = true;
+
+			} catch (System.SystemException exp) {
+				Console.WriteLine("Impossible to stop client now");
+			}
+
+			return ret;
+		}
+
+
+		public void RunClient2() {
+			ProtectedRessource ressource = new ProtectedRessource();
+		}
+
+	}
+
+
+	public class ProtectedRessource {
+
+		private String error = "";
+
+
+		public ProtectedRessource() {
+			try {
+				bool constructorMutexCreated;
+				Mutex mutex = new Mutex(true, "ConstructorTraceMutex", out
+constructorMutexCreated);
+
+				if ( ! constructorMutexCreated) mutex.WaitOne();
+
+				mutex.ReleaseMutex();
+			} catch (System.SystemException exp) {
+				error += "ProtectedRessource : " + exp.Message;
+			}
+		}
+
+	}
+
+}
+
+2. compile with 'mcs test.cs'
+
+3. run with mono test.exe
+
+
+Actual Results:
+The program almost always crashes after start&stop the thread 3 or 4 times.
+Sometimes there is a message which appears : "GC Warning: Out of Memory! 
+Returning NIL!".
+
+
+Expected Results:
+The program start&stop the thread 5 times and then proposes to us to quit
+without difficulties.
+
+
+How often does this happen?
+always (almost)
+a message often appears : "GC Warning: Out of Memory!  Returning NIL!"
+
+
+Additional Information:
+this program seems to run perfectly with 'mint test.exe'