Overriden method not detected ?
chmike via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 3 06:27:41 PDT 2016
On Friday, 3 June 2016 at 12:41:39 UTC, Jonathan M Davis wrote:
...
> On a side note, be warned that you almost certainly shouldn't
> be using __gshared like this. It's intended for interacting
> with C code not for D objects to be marked with D. As far as
> the type system is concerned, __gshared isn't part of the type,
> and the variable will be treated as thread-local by all of the
> code that uses it, which can result in really nasty, subtle
> bugs when the compiler starts doing stuff like optimizations.
> If you want to be sharing D objects across threads, you really
> should be using shared so that the compiler knows that it's
> shared across threads and will treat it that way.
Thanks to point this out. What does shared really do behind the
scene ?
Does it add synchronization instructions ?
In my case I really don't want the compiler to add
synchronization instructions because the objects are immutable
from the user perspective. This is enforced by the interface. Tho
objects are fully instantiated in a private static this() {}
function which shouldn't be affected by multi-threading since it
is executed at startup.
The unpleasant side effect of shared is that I then have to use
shared(Info) instead of the shorter type name Info.
What are the subtle and nasty bugs you are referring to ?
More information about the Digitalmars-d-learn
mailing list