digitalmars.D.learn - I need a detailed document about druntime.
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (28/28) Oct 11 2021 I want to know what happens if either Runtime.initialize or
- Adam D Ruppe (4/6) Oct 11 2021 That what it does by itself, you can call it and it has an
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/10) Oct 11 2021 Thank you for your response. But this confuses me:
- Adam D Ruppe (15/16) Oct 11 2021 It is so the refcount works out.
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (2/20) Oct 11 2021 That makes sense, now I see, thank you again Adam.
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); } } } ```
Oct 11 2021
On Monday, 11 October 2021 at 14:56:19 UTC, Ferhat Kurtulmuş wrote:What I want is to bypass runtime initialization if it is already initialized.That what it does by itself, you can call it and it has an internal count.
Oct 11 2021
On Monday, 11 October 2021 at 15:09:12 UTC, Adam D Ruppe wrote:On Monday, 11 October 2021 at 14:56:19 UTC, Ferhat Kurtulmuş wrote:Thank you for your response. But this confuses me: "Each call to initialize must be paired by a call to terminate.' https://dlang.org/library/core/runtime/runtime.initialize.htmlWhat I want is to bypass runtime initialization if it is already initialized.That what it does by itself, you can call it and it has an internal count.
Oct 11 2021
On Monday, 11 October 2021 at 15:18:11 UTC, Ferhat Kurtulmuş wrote:"Each call to initialize must be paired by a call to terminate.'It is so the refcount works out. When you call initialize, it does something like: if(refcount == 0) actually intialize; // calls constructors etc refcount++; When you call terminate, it does: refcount--; if(refcount == 0) actually terminate; // calls destructors etc If you don't pair it, the refcount will be off, so the next call to terminate will still see ref > 0 and not actually terminate. The D main inserts a call to init before main and a call to terminate after main automatically.
Oct 11 2021
On Monday, 11 October 2021 at 15:24:07 UTC, Adam D Ruppe wrote:On Monday, 11 October 2021 at 15:18:11 UTC, Ferhat Kurtulmuş wrote:That makes sense, now I see, thank you again Adam."Each call to initialize must be paired by a call to terminate.'It is so the refcount works out. When you call initialize, it does something like: if(refcount == 0) actually intialize; // calls constructors etc refcount++; When you call terminate, it does: refcount--; if(refcount == 0) actually terminate; // calls destructors etc If you don't pair it, the refcount will be off, so the next call to terminate will still see ref > 0 and not actually terminate. The D main inserts a call to init before main and a call to terminate after main automatically.
Oct 11 2021