Why are globals set to tls by default? and why is fast code ugly by default?
Nick Treleaven
nick at geany.org
Fri Mar 31 10:26:32 UTC 2023
On Sunday, 26 March 2023 at 20:39:21 UTC, ryuukk_ wrote:
> if my code doesn't do threads, why should i put my variable
> into TLS?
I don't think writing __gshared is much of a burden. You can use
-vtls to print out all variables that are TLS, and add that to an
automated test to check you don't have any accidentally. I have
thought before that a --no-threads compiler switch that does not
link the key thread functions but makes __gshared the default
might be a good enhancement for your use case. Then if you
accidentally call some code that uses std.parallelism internally
you would get a link error.
> If i want fast code, why should i make use of ugly syntax?
1. If you want fast code, why aren't you using threads?
2. By default D supports threads and accidental data races are
far worse than ugly syntax.
More information about the Digitalmars-d-learn
mailing list