On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote:
What i do not understand is the reasoning behind choosing tls global by default in D

Because the language maintainers decided that they want to emphasize the actor model with no default shared state in the language.

This is quite beneficial, BTW, as multiprocessor programming is by no means an easy problem, so the language just pushes you towards the error-free code by default.

As for `__gshared`, this is intended only for interfacing with C and other languages where global variables is the default way of doing things.

This may seem ugly, but if you write your program completely in D and want to avoid TLS, why don't you avoid globals at all?

Just allocate some state on the stack and pass it to your functions as `ref`.

This way it will actually be much cleaner and easy to understand and test, because global variables are tempting to be mutated, which makes the program control flow much less transparent.

Reply via email to