www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - Make TLS explicit

A long time ago, global variables and static variables in D were 
changed to be thread local by default. I think this has proven to 
mostly be a bad idea, for a few reasons:

- Violates the “looks like C principle”: Code that looks like C 
should either behave the same as C or not compile.
- Unexpected: No other language defaults to TLS.
- Unwanted: Most of the time you don’t actually want thread local 
variables. If you want global state you either want immutability 
or synchronized access (mutexes) through something like shared. 
TLS is the exception.
- Not as safe as it looks: thread local variables still have many 
of the problems of global variables, such as having to worry 
about function re-entrancy.

So I propose to make it an error to have it be unspecified if a 
static variable is shared, __gshared, immutable or thread local. 
Additionally, add a thread_local storage class so you can 
explicitly opt into TLS for when you actually want that.

Changing this might require a new edition, but who knows.
Apr 16