Thread overview
[Issue 19487] Thread never detaches after spawn
Dec 17, 2018
anonymous4
Dec 17, 2018
anonymous4
Dec 11, 2019
er.krali@gmail.com
Dec 17, 2022
Iain Buclaw
December 14, 2018
https://issues.dlang.org/show_bug.cgi?id=19487

Nikolay (unDEFER) Krivchenkov <undefer@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |undefer@gmail.com

--
December 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19487

--- Comment #1 from anonymous4 <dfj1esp02@sneakemail.com> ---
try this:
---
void main()
{
    for (int i=0; i<1000; i++)
    {
        spawn(&thread);
    }
    thread_joinAll();
    writefln("Collect");
    GC.collect();
    Thread.sleep(10.seconds);
}
---

--
December 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19487

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|All                         |Linux

--
December 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19487

--- Comment #2 from Nikolay (unDEFER) Krivchenkov <undefer@gmail.com> ---
anonymous4, and.. it doesn't work.

--
December 11, 2019
https://issues.dlang.org/show_bug.cgi?id=19487

er.krali@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |er.krali@gmail.com

--- Comment #3 from er.krali@gmail.com ---
I think that the issue is that the thread is never joined properly.

I have an application that listens to a socket and spawns a new thread for each (very short-lived) incoming connection, and I have to run `joinLowLevelThread` to get a proper cleanup. And for that each running thread has to send back its id to its parent using `Thread.getThis.id`.

Also, thread_joinAll doesn't work in my case either because it waits for all the threads... in order. And I happen to have some other long lived threads, so it blocks there and never cleans up anything.

Part of the issue is that you can't get the underlying Thread object from `spawn`, so there's no way to join it. The other part, of course, is that this is not taken care of automatically.

Incidentally, it also leaks memory like hell, I can see the GC usage continuously growing and no amount of GC.collect or GC.minimize can get rid of it, so the data must be being kept somewhere...

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=19487

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--