[Mono-bugs] [Bug 44067][Maj] New - thread handles leaked

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Mon, 2 Jun 2003 22:24:41 -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 gonzalo@ximian.com.

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

--- shadow/44067	Mon Jun  2 22:24:41 2003
+++ shadow/44067.tmp.10229	Mon Jun  2 22:24:41 2003
@@ -0,0 +1,65 @@
+Bug#: 44067
+Product: Mono/Runtime
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: gonzalo@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: thread handles leaked
+
+Given this test case:
+
+----
+using System.Threading;
+
+class C
+{
+	static AutoResetEvent evnt = new AutoResetEvent (false);
+
+	static void cb ()
+	{
+		evnt.Set ();
+	}
+	
+	static void Main ()
+	{
+		for (int i = 1; i <= 5000; i++) {
+			Thread thread = new Thread (new ThreadStart (cb));
+			thread.Start ();
+			evnt.WaitOne ();
+			thread = null;
+			if (i % 10 == 0) {
+				Console.WriteLine (i);
+				GC.Collect ();
+				GC.WaitForPendingFinalizers ();
+			}
+		}
+	}
+}
+
+----
+
+Enable HEAVY_DEBUG in mono/io-layer/handles.c, optionally modifying the
+line that calls print_handle_count to only display WAPI_HANDLE_THREAD.
+
+Compile and run.
+
+You'll see that the number of thread handles being used never decreases.
+
+Additional information:
+I tried CloseHandle in metadata/threads.c:thread_cleanup, but still
+semaphore handles are leaked.
+
+ves_icall_System_Threading_Thread_Thread_free_internal is never called.
+
+May be the pointer in 'threads' (saved in handle_store) prevents the GC
+from collecting the thread?