Bug 2439 – static ~this() cannot be used to shutdown threads
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-11-02T12:31:00Z
Last change time
2015-06-09T01:20:25Z
Assigned to
bugzilla
Creator
sludwig
Comments
Comment #0 by sludwig — 2008-11-02T12:31:13Z
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...)
Comment #1 by sean — 2008-11-02T16:18:08Z
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.