I need a detailed document about druntime.

Ferhat Kurtulmuş aferust at gmail.com
Mon Oct 11 14:56:19 UTC 2021


I want to know what happens if either Runtime.initialize or 
terminate is called without matching each other. And why there is 
no ready-to-use thing like initCount which is accessible in the 
code? What I want is to bypass runtime initialization if it is 
already initialized. The below code is my workaround, but it can 
only keep track of my initializations, not the one that 
automatically get fired where there is a dmain.

Should İ use "bool runMain" to differentiate between the 
compilations of dll and executable?

```d
private {
     import core.runtime;
     import core.atomic;

     shared size_t initCount;

     void initRT(){
         if(!atomicLoad!(MemoryOrder.acq)(initCount)){
             Runtime.initialize();
             atomicOp!"+="(initCount, 1);
         }
     }

     void termRT(){
         if(atomicLoad!(MemoryOrder.acq)(initCount) > 0){
             Runtime.terminate();
             atomicOp!"-="(initCount, 1);
         }
     }
}
```


More information about the Digitalmars-d-learn mailing list