On Wednesday, 3 October 2018 at 21:39:12 UTC, welkam wrote:
string a = "test";
is a variable that mutates so it should be thread local. Also
ASM output shows that these variables are not optimized away so
compiler should output something but it doesnt. Or I dont
understand thread local storage.
Thread-local storage is memory allocated for each thread.
Only static non-immutable variables go there. Regular variables
on the stack aren't explicitly placed in any TLS, they're, well,
on the stack as it is.
For example, add this to the top of your program after "import
std.stdio;":
int IAmInTls;
Then when you compile with -vtls, dmd will report that indeed a
variable named "IAmInTls" will be placed in thread-local storage.
That's because module-level variables are static.
If, however, you declare it as immutable int, it won't go to TLS,
it'll become a regular global.
Same will happen if you add a static variable inside the main()
function, e.g. a "static string str;".