This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 5650 - Unable to start thread during AppDomain.ProcessExit event
: Unable to start thread during AppDomain.ProcessExit event
Status: NEW
Product: Runtime
Classification: Mono
Component: misc
: unspecified
: PC Windows
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-06-14 10:27 EDT by Jeroen Frijters
Modified: 2012-07-19 13:10 EDT (History)
5 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments

Description Jeroen Frijters 2012-06-14 10:27:05 EDT
The following program hangs on Mono (and runs as expected on .NET):

using System;
using System.Threading;

class Test
{
  static void Main()
  {
    AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
    Console.WriteLine("should exit!");
  }

  static void Dummy() {
  }

  static void OnProcessExit(object sender, EventArgs e) {
    Console.WriteLine("starting shutdown hook");
    Thread t = new Thread(Dummy);
    t.Start();
    t.Join();
    Console.WriteLine("done");
  }
}

While it's arguably not a great idea to start a new thread during exit, this is
the mechanism that Java uses for application cleanup handlers and I've
implemented it as-is in IKVM and it works on .NET. If there is a good reason
not to support this, I'd be happy to add a workaround to IKVM, but maybe it is
easy to fix in the Mono runtime.
Comment 1 Zoltan Varga 2012-06-14 17:41:04 EDT
This is probably a mono bug, we run the ProcessExit handler during shutdown,
when thread creation is disabled. Its not very easy to fix.
Comment 2 Jeroen Frijters 2012-06-15 02:40:24 EDT
As I said, I'm fine with it not being fixed, but I would like to suggest two
changes:
- Thread.Start() should throw an exception under these conditions
- Thread.Join() should return immediately
Comment 3 Rodrigo Kumpera 2012-07-19 13:10:28 EDT
I guess we need to give ProcessExit the same treatment we did with the
appdomain unload event and make it run as an independent step of the shutdown
process.

But, yeah, it's a non-trivial change to an already convoluted part of the
runtime, shutdown.

Note You need to log in before you can comment on or make changes to this bug.