Why are globals set to tls by default? and why is fast code ugly by default?

ryuukk_ ryuukk.dev at gmail.com
Sun Mar 26 20:36:37 UTC 2023


On Sunday, 26 March 2023 at 18:25:54 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> Having TLS by default is actually quite desirable if you like 
> your code to be safe without having to do anything extra.
>
> As soon as you go into global to the process memory, you are 
> responsible for synchronization. Ensuring that the state is 
> what you want it to be.
>
> Keep in mind that threads didn't exist when C was created. They 
> could not change their approach without breaking everyone's 
> code. So what they do is totally irrelevant unless its 1980.
>
> I think its the correct way around. You can't accidentally 
> cause memory safety issues. You must explicitly opt-into the 
> ability to mess up your programs state.

It's never desirable to have it by default, the consensus should 
be: let the developer make the choice, currently the consensus is 
to punish the developer who want to make the choice

Golang doesn't even have thread local storage, yet they do very 
well

D doesn't have coroutines, D doesn't do anything special, it just 
forces you to uglyfy your code to opt out

``__gshared`` is ugly to write, ugly to read, there must be a 
better solution




More information about the Digitalmars-d-learn mailing list