shared - i need it to be useful

Nicholas Wilson iamthewilsonator at hotmail.com
Sat Oct 20 16:48:05 UTC 2018


On Saturday, 20 October 2018 at 09:04:17 UTC, Walter Bright 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,

Quoting Wikipedia:

>two pointers A and B which have the same value, then the name 
>A[0] aliases the name B[0]. In this case we say the pointers A 
>and B alias each other. Note that the concept of pointer 
>aliasing is not very well-defined – two pointers A and B may or 
>may not alias each other, depending on what operations are 
>performed in the function using A and B.

In this case given the above: `a[0]` does not alias `b[0]` 
because `b[0]` is ill defined under Manu's proposal, because the 
memory referenced by `a` is not reachable through `b` because you 
can't read or write through `b`.

> by code that believes it is unshared

you cannot `@safe`ly modify the memory  through `b`, `a`'s view 
of the memory is unchanged in @safe code.

> and, code that believes it is shared.

you cannot have non-atomic access though `b`, `b` has no @safe 
view of the memory, unless it is atomic (which by definition is 
synchronised).

>This is not going to work.

Aú contraire.



More information about the Digitalmars-d mailing list