`shared`...

Manu turkeyman at gmail.com
Mon Oct 1 23:16:07 UTC 2018


On Mon, Oct 1, 2018 at 11:45 AM deadalnix via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Monday, 1 October 2018 at 02:29:40 UTC, Manu wrote:
> > I feel like I don't understand the design...
> > mutable -> shared should work the same as mutable -> const...
> > because
> > surely that's safe?
> >
>
> Nope. Consider.
>
> struct A {
>     A* a;
> }
>
> void foo(shared A* a) {
>      a.a = new shared(A))();
> }
>
> Now you have effectively made a.a accessible as a mutable when it
> is shared.

I think you mean `scope shared A* a`, but that's fine.
This is okay; the new 'A' is not actually shared, so the demotion to
thread-local on return is actually correct.

I think I can imagine constructions like this that demonstrate the
issue you're trying to suggest.
Is there a tighter ruleset that can prevent the sort of escape you're
trying to demonstrate? We need to find the right rules...


More information about the Digitalmars-d mailing list