rt_init, rt_term and _initCount
Rainer Schuetze via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 21 12:40:52 PDT 2016
On 20.10.2016 09:17, Benjamin Thaut wrote:
> This is a topic really specific to druntime, I don't know a better place
> to put it though.
>
> rt_init increases the _initCount and rt_term decreases it and only
> terminates the runtime in case the _initCount reaches zero (see dmain2.d)
[...]
> The problem is step 5) in the above list. When the main executable
> leaves dmain the runtime should be deinitialized no matter if any dll is
> still loaded or not. If this would be the case the module Dtors would be
> calle din the correct order. I can't remove the rt_init calls from the
> dll loading code however because that would mean when loading a d-dll
> into a C process druntime would never be initialized. So I'm thinking of
> adding a force parameter to rt_term which will always deinitialize
> druntime disregarding the _initCount. This feels like a hack though.
>
> Any suggestions how to solve this problem? Who are other platforms doing
> it?
I don't think the current rt_init/rt_exit function are suitable for DLLs
or executables that are using a shared druntime library.
The wrapper around main in the executable should work just as any DLLs'
DllMain, i.e. it should register/unregister its own data segments with
the GC and run its shared and TLS module constructors/decoontructors.
Everything else should be handled by the druntime DLL.
More information about the Digitalmars-d
mailing list