Sharing in D

Sean Kelly sean at invisibleduck.org
Fri Aug 1 09:51:15 PDT 2008


== Quote from superdan (super at dan.org)'s article
> Steven Schveighoffer Wrote:
> > "Walter Bright" wrote
> > >
> > > Non-shared can be implicitly cast to shared, as that is always safe. Just
> > > not the other way.
> >
> > How is that possible?
> >
> > shared int *x;
> >
> > void foo(shared int *y)
> > {
> >     x = y;
> > }
> >
> > int *x2;
> >
> > void bar()
> > {
> >     foo(x2);
> > }
> >
> > After calling bar, isn't x2 now both shared (as x) and unshared at the same
> > time?  I think you need casts for both ways.
> looks like walt has a problem in his hands :))

That, or 'shared' applies only to the pointer, not to the value being pointed to.
However, given the const system I'd be inclined to think that 'shared' may be
transitive, in which case yeah, you've got a problem :-)


Sean



More information about the Digitalmars-d mailing list