On Thursday, May 25, 2017 19:57:17 Ola Fosheim Grøstad via Digitalmars-d 
wrote:
> On Thursday, 25 May 2017 at 14:56:25 UTC, Jonathan M Davis wrote:
> > able to do so with the excuse that shared is not complete. But
> > the idea that you do almost nothing with an object that is
> > shared without casting it first (after protecting it
> > appropriately with a mutex of course) except for using atomics
> > seems to be too much for many folks, even though aside from the
> > cast, the way you actually use a shared object is basically
> > what you'd do in C/C++. I'd say that ultimately, shared is more
> > for storing the object and protecting it against operations
> > that could operate on it incorrectly than it is for actually
> > operating on the object.
>
> You should look at Pony which has a sound type system for
> transitioning objects read/write local/shared:
>
> https://tutorial.ponylang.org/capabilities/reference-capabilities.html
>
> It is kinda like Rust, but more advanced.

Oh, having some sort of ownership model or something similar in the type
system which made it possible to know when something was only referenced
once on a thread and thus could be passed safely to another and things like
that would be very cool. For instance, it would make std.concurrency far
easier to use safely with mutable data. The problem is that it seems that in
order to for that to be possible, it adds quite a bit of complication to the
language. Certainly, from what I know of Rust, it's far more complicated
because of that sort of thing, and glancing over that link on Pony, it
looks like it's getting a fair bit of complication as well in order to deal
with the problem.

With D, having shared (and thus having everything else be thread-local)
simplifies a lot of stuff, leaving the nasty stuff with regards to threads
to shared, which is great, but dealing with the stuff that involves sharing
across threads then requires that the programmer be much more careful than
would be the case if the type system were actually helping you beyond
preventing you from doing stuff that isn't thread safe to a shared object
without casting it to thread-local first. So, we're stuck with an annoying
area that would be great to clean up, but cleaning it up seems like it
requires complicating everything else...

I don't know what the right answer is. Rust seems to get both praise and
complaints about its approach - as do we for ours. But both approaches are
safer than what you get with C/C++.

- Jonathan M Davis


Reply via email to