Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose an easy way in CLR hosting APIs to make shutdown work as in Desktop CLR #4532

Closed
muratg opened this issue Sep 30, 2015 · 2 comments
Closed
Assignees
Milestone

Comments

@muratg
Copy link

muratg commented Sep 30, 2015

From aspnet/dnx#1589

using System;
using System.Threading;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main()
        {
            var t = new Thread(() => { while (true); });
            t.IsBackground = false;
            t.Start();
            Console.WriteLine("finished");
        }
    }
}

When ran with DNX, this has different behavior on CoreCLR and CLR. On CLR this waits forever, while on CoreCLR, it prints "finished" and exits immediately.

If there was a way to make hosting CoreCLR apps (which needed by DNX) behave the same on shutdown as Desktop CLR apps, we could make these behave the same.

@janvorli
Copy link
Member

It looks like the mechanism is present even for CoreCLR, but never kicks in. The Assembly::ExecuteMainMethod calls RunMainPost method that is responsible for waiting for the other threads, but it calls it conditionally based on the stringArgs parameter being NULL or not being NULL.
On CoreCLR, the stringArgs is never NULL and so the wait is never executed.
It seems that adding a bool parameter to the ExecuteMainMethod that would indicate whether to wait or not instead of deriving it from the value of the stringArgs should fix the problem.

@janvorli
Copy link
Member

Fixed by dotnet/coreclr#2164

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@msftgits msftgits added this to the 1.0.0-rc2 milestone Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants