What exactly shared means?
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 5 04:59:26 PST 2015
On Saturday, 3 January 2015 at 23:11:08 UTC, Jonathan M Davis via
Digitalmars-d-learn wrote:
> Ideally, you would never cast away shared, and it would be cast
> away for you
> by the compiler in sections of code where it can guarantee that
> it's safe to
> do so (that was part of the idea behind synchronized classes).
> But that's
> incredibly difficult to do, particularly in a useful way, so we
> don't
> currently have it. And yes, that sucks, and we definitely want
> to fix it,
> but I still think that it's far better than having everything
> be shared by
> default like you get in languages like C++ and Java.
Efficient automatic synchronization is difficult, yes. You can
try to tie groups of entities to a lock, but that will only work
in some scenarios.
To me it sounds like having everything shared by default is the
most conservative (safest) approach, and that it would make sense
to put restrictions on parameters when you need more performance.
If D's approach should make sense the compiler would allowed to
elide atomics on members of an object the reference to the object
is not marked as "shared". That can easily go horribly wrong.
I am also not overly happy with D making TLS default. That means
new threads instantiate a lot of unused memory if the workload is
heterogeneous (different threads do different type of work). TLS
only make sense for things that all threads need.
More information about the Digitalmars-d-learn
mailing list