Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

CoreRT quits when Foreground threads are running #8246

Closed
Suchiman opened this issue Jul 25, 2020 · 2 comments
Closed

CoreRT quits when Foreground threads are running #8246

Suchiman opened this issue Jul 25, 2020 · 2 comments

Comments

@Suchiman
Copy link
Contributor

This code will print Hello World until all eternity on CoreCLR but exit immediately and print nothing on CoreRT.

using System;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var t = new Thread(Meh);
        t.IsBackground = false;
        t.Start();
    }

    private static void Meh(object obj)
    {
        while (true)
        {
            Thread.Sleep(10);
            Console.WriteLine("Hello World!");
        }
    }
}

I suppose it would need to check before this line

RhpShutdown();
if there are any Foreground threads still running, how does this work on CoreCLR?

@jkotas
Copy link
Member

jkotas commented Jul 25, 2020

CoreCLR has this logic in ThreadStore::WaitForOtherThreads https://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/src/coreclr/src/vm/threads.cpp#L5704 . It is a counter of non-background thread + event that is set whenever this counter goes towards zero.

These two TODOs look related:

@jkotas
Copy link
Member

jkotas commented Oct 16, 2020

Fixed by dotnet/runtimelab#235

@jkotas jkotas closed this as completed Oct 16, 2020
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

2 participants