On Thursday, 9 July 2015 at 14:57:56 UTC, Márcio Martins wrote:
On Thursday, 9 July 2015 at 14:03:18 UTC, Jonathan M Davis
wrote:
On Thursday, 9 July 2015 at 12:39:00 UTC, Márcio Martins wrote:
[...]
Well, the compiler is free to assume that a variable that is
not marked as shared is thread-local. So, it's free to make
optimizations based on that. So, for instance, it can know for
a fact that
[...]
But this is what a C/C++ compiler would do, unless you your
data is qualified as volatile. I believe __gshared also implies
the volatile behavior, right? I wouldn't make sense any other
way.
So basically, __gshared is like saying "I want the C/C++
behavior, and I accept I am all on my own as the compiler will
not help me".
If you think volatile is going to help you with concurency, you
gonna have bad time.
The only thing volatile does is to prevent register promotion of
the variable. It is usefull for MMIO, it doesn't provide
guarantee for multithreading.