Thread overview
[Issue 2439] New: static ~this() cannot be used to shutdown threads
Nov 02, 2008
d-bugmail
Nov 02, 2008
d-bugmail
Nov 03, 2008
Sönke Ludwig
November 02, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2439

           Summary: static ~this() cannot be used to shutdown threads
           Product: D
           Version: 2.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: ludwig@informatik.uni-luebeck.de


In src/druntime/src/compiler/dmd/dmain2.d:301 thread_joinAll() is called before
_moduleDtor(). This makes it impossible to perform thread shutdown inside of a
module destructor because the thread_joinAll() call will wait indefinitely if
there are still threads waiting for a shutdown signal.

Moving thread_joinAll between _moduleDtor() and gc_term() should fix the issue.

(not sure if this should go here or into the trac issue tracker for
druntime...)


-- 

November 02, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2439


sean@invisibleduck.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX




------- Comment #1 from sean@invisibleduck.org  2008-11-02 16:18 -------
It's not unlikely that a thread may depend on static data, so by moving thread_joinAll() until after the module dtors are called we would be pulling the rug out from under these threads.  Instead, I suggest making threads that interact with the module shutdown process into daemon threads by using the "isDaemon" property.  These threads are ignored during thread_joinAll() and, left alone, will run until the process ends.


-- 

November 03, 2008
d-bugmail@puremagic.com schrieb:
> http://d.puremagic.com/issues/show_bug.cgi?id=2439
> 
> 
> sean@invisibleduck.org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|NEW                         |RESOLVED
>          Resolution|                            |WONTFIX
> 
> 
> 
> 
> ------- Comment #1 from sean@invisibleduck.org  2008-11-02 16:18 -------
> It's not unlikely that a thread may depend on static data, so by moving
> thread_joinAll() until after the module dtors are called we would be pulling
> the rug out from under these threads.  Instead, I suggest making threads that
> interact with the module shutdown process into daemon threads by using the
> "isDaemon" property.  These threads are ignored during thread_joinAll() and,
> left alone, will run until the process ends.
> 

Ah OK.. I didn't know about that property. That approach is definitly workable, albeit maybe a little non-obvious. THanks for the quick feedback.