implicit conversions to/from shared

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 11 06:23:42 PDT 2016


On 07/11/2016 02:54 PM, Steven Schveighoffer wrote:
> I think you misunderstand the problem here.

Yes.

> Conversion means changing
> the type.
>
> Once you have loaded the shared data into a register, or whatever, it's
> no longer shared, it's local. Writing it out to another place doesn't
> change anything. It's once you add references into the mix where you may
> have a problem.

Right.

> What I think you mean (and I think you realize this now), is that the
> actual copying of the data should not be implicitly allowed. The type
> change is fine, it's the physical reading or writing of shared data that
> can cause issues. I agree we should extend the rules to prevent this.

Exactly.

> In other words:
>
> shared int x;
>
> void main()
> {
>     // ++x; // not allowed
>     int x2 = x + 1; // but this is
>     x = x2; // and it shouldn't be
> }

I think I would prefer if the compiler would generate atomic operations, 
but I'm clearly far from being an expert on any of this. Simply 
rejecting the code would be fine with me, too.

Also:

shared int x;
shared int y;
x = y; /* should be rejected too (or be atomic, if that's even possible) */


More information about the Digitalmars-d mailing list