Bug 9641 – Wrong module init order when a thread is created in a module ctor

Status
NEW
Severity
critical
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-03T05:51:59Z
Last change time
2024-12-07T13:32:18Z
Assigned to
No Owner
Creator
Benjamin Thaut
Moved to GitHub: dmd#17249 →

Attachments

IDFilenameSummaryContent-TypeSize
1198repro.ziprepro caseapplication/zip722

Comments

Comment #0 by code — 2013-03-03T05:51:59Z
Created attachment 1198 repro case When you create a new thread in a module constructor the module tls constructors will be run before all module constructors have been run. This is incorrect behavior as the spec states "Shared static constructors on all modules are run before any static constructors." See attached repro case. Tested with dmd 2.062
Comment #1 by code — 2014-05-11T15:27:25Z
I think the fix would need a mutex which blocks all created threads until all shared module constructors are finished. This might easily cause deadlocks though.
Comment #2 by dlang-bugzilla — 2017-07-18T14:06:16Z
(In reply to Martin Nowak from comment #1) > I think the fix would need a mutex which blocks all created threads until > all shared module constructors are finished. This might easily cause > deadlocks though. Sounds very similar to how Windows blocks threads created in DllMain. The deadlock issue is there as well (threads will remain suspended until initialization completes).
Comment #3 by robert.schadek — 2024-12-07T13:32:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17249 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB