druntime thread (from foreach parallel?) cleanup bug

mw mingwu at gmail.com
Tue Nov 1 19:49:47 UTC 2022


On Tuesday, 1 November 2022 at 18:18:45 UTC, Steven Schveighoffer 
wrote:

>> 
>> And I just noticed, one of the thread trace points to here:
>> 
>> https://github.com/huntlabs/hunt/blob/master/source/hunt/util/DateTime.d#L430
>> 
>> ```
>> class DateTime {
>>    shared static this() {
>>      ...
>>      dateThread.isDaemon = true;  // not sure if this is 
>> related
>>    }
>> }
>> ```
>> 
>> in the comments, it said: "BUG: ... crashed".  Looks like 
>> someone run into this (cleanup) issue already, but unable to 
>> fix it.
>> 
>> Anyway I logged an issue there:
>> 
>> https://github.com/huntlabs/hunt/issues/96
>> 
>> 
>
> Oh yeah, isDaemon detaches the thread from the GC. Don't do 
> that unless you know what you are doing.
>

Maybe the hunt library author doesn't know. (My code does not 
directly use this library, it got pulled in by some other 
decencies.)


Currently, the `isDaemon` doc does not mention this about this:

https://dlang.org/library/core/thread/threadbase/thread_base.is_daemon.html

Sets the daemon status for this thread. While the runtime will 
wait for all normal threads to complete before tearing down the 
process, daemon threads are effectively ignored and thus will not 
prevent the process from terminating. In effect, daemon threads 
will be terminated automatically by the OS when the process exits.

Maybe we should add to the doc?


BTW, what is exactly going wrong with their code?

I saw the tick() method call inside the anonymous `dateThread` is 
accessing these two stack variables of shared static this():

https://github.com/huntlabs/hunt/blob/master/source/hunt/util/DateTime.d#L409

         Appender!(char[])[2] bufs;
         const(char)[][2] targets;

Why does this tick() call work after the static this() finished 
in a normal run?

Why the problem only shows up when program finish?




More information about the Digitalmars-d-learn mailing list