[Mono-bugs] [Bug 651296] New: Calling Environment.Exit only kills the calling thread, not the main thread
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu Nov 4 09:47:39 EDT 2010
https://bugzilla.novell.com/show_bug.cgi?id=651296
https://bugzilla.novell.com/show_bug.cgi?id=651296#c0
Summary: Calling Environment.Exit only kills the calling
thread, not the main thread
Classification: Mono
Product: Mono: Runtime
Version: 2.8.x
Platform: x86
OS/Version: Windows 7
Status: NEW
Severity: Normal
Priority: P5 - None
Component: misc
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: imphasing at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7
Calling Environment.Exit from a second thread kills that thread, but not the
main thread, leading to somewhat strange results.
Test case:
using System;
using System.Threading;
class ThreadTest
{
public static void Main()
{
ConsoleKeyInfo cki;
Thread second = new Thread(new ThreadStart(SecondThread));
Console.WriteLine("[Thread1] Thread ID: " +
System.AppDomain.GetCurrentThreadId());
second.Start();
Console.WriteLine("[Thread1] Second thread started. Should be exiting
any second...");
while(true)
{
Console.WriteLine("[Thread1] Looping on readkey... press 'X' to
exit.");
Console.WriteLine("[Thread1] Has shutdown started? " +
Environment.HasShutdownStarted.ToString());
cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.X)
break;
}
}
public static void SecondThread()
{
Console.WriteLine("[Thread2] Thread ID: " +
System.AppDomain.GetCurrentThreadId());
Console.WriteLine("[Thread2] Calling Environment.Exit...");
Environment.Exit(58);
}
}
I can confirm that this works as expected on MS's CLR, as well as on Linux
using 2.6.7 and 2.8, so this bug seems to be Windows-specific.
Reproducible: Always
Steps to Reproduce:
1. Run the program
2. Note that it kills off the second thread, but not the main thread, as it
continues to accept input
3.
--
Configure bugmail: https://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