shared - i need it to be useful

Manu turkeyman at gmail.com
Sat Oct 20 18:24:10 UTC 2018


On Sat, Oct 20, 2018 at 2:05 AM Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 10/19/2018 11:18 PM, Manu wrote:
> > The reason I ask is because, by my definition, if you have:
> > int* a;
> > shared(int)* b = a;
> >
> > While you have 2 numbers that address the same data, it is not actually aliased
> > because only `a` can access it.
>
> They are aliased, by code that believes it is unshared, and code that believes
> it is shared.

This situation could only occur if you do unsafe code badly.
Unlike today, where you must do unsafe code to do any interaction of
any kind, you will be able to do fully-safe interaction with the stack
of tooling.
In that world, any unsafe code and *particularly* where it interacts
with shared will be an obnoxious and scary code smell.
If it was possible to interact with shared safely, it would be
blindingly suspicious when people are likely to be shooting themselves
in the foot.

The situation you describe here is *exactly* what we have right now,
and I'm trying to prevent that.

> This is not going to work

This is an unfair dismissal. Have you tried it? I have.
Write me the rules in a patch that I can take for a drive and
demonstrate what the stack looks like.

> > Exclusively distinguishing shared and unshared data is not an interesting
> > distinction if shared data has no access.
>
> Somehow, you still have to find a way to give the shared path access, through a
> gate or a cast or a lock or whatever.

I'm not sure you've understood the proposal.
This is the reason for the implicit conversion. It provides safe
transition. That's why I'm so insistent on it.

> And then it breaks, because two different
> threads are accessing the same data each thinking that data is not shared.

This can only occur if you deliberately violate your @safety, and then mess up.
This is *exactly* the interaction prescribed to shared today. This is
what I'm fixing by making a fully @safe path!

I think you demonstrate here that you haven't understood the reason,
or the semantics of my proposal. I'm not sure how to clarify it, what
can I give you?


More information about the Digitalmars-d mailing list