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

Steven Schveighoffer schveiguy at gmail.com
Sun Mar 26 19:08:32 UTC 2023


On 3/26/23 2:07 PM, ryuukk_ wrote:
> Hi,
> 
> It's common knowledge that accessing tls global is slow 
> http://david-grs.github.io/tls_performance_overhead_cost_linux/
> 
> What i do not understand is the reasoning behind choosing tls global by 
> default in D

If you know a variable is not `shared`, then you know it can only be 
accessed from the current thread. This has huge implications for thread 
access.

However, one problem that D has no good solution is passing thread-local 
data to another thread (to be owned by the new thread, and no access in 
the current thread). That's typically the most common use case for 
"shared data".

-Steve


More information about the Digitalmars-d-learn mailing list