Walter Bright wrote:
Denis Koroskin wrote:
I've recently updated to DMD2.035 (from DMD2.031 because all the later
versions had issues with imports) and for the first time faced
problems with shared modifier.
I don't need shared and all my globals are __gshared (they are
globally unique instances that don't need per-thread copies).
I don't understand. Are you running multiple threads? Are those threads
accessing globals?
A function that accesses shared data has to put in fences. There's no
way to have the same code deal with shared and unshared code.
Acquiring a lock on a non-shared instance is safe, just an unnecessary
expense. I would have looked into optimizing this expense away rather
than punting the problem to the programmer.
As an escape from the type system, you can always cast away the
shared-ness. But I wonder about code that both uses global variables
shared across threads that don't need synchronization?
Maybe the methods are mostly inherently threadsafe. Only a small portion
requires locking, so it's more efficient to handle it manually.