Sharing in D

superdan super at dan.org
Fri Aug 1 08:32:09 PDT 2008


Sean Kelly Wrote:

> == Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> > superdan wrote:
> > > Walter Bright Wrote:
> > >>> So "shared" will tell the compiler to automatically fence, etc?
> > >> Yes.
> > >
> > > yech. so i write this:
> > >
> > > ++a; ++b; ++c;
> > >
> > > and very different code comes down the pike depending on a or b or c
> > > being shared. not easy to clarify the code is correct. this ain't
> > > cool.
> > If conventional code were generated for i++, and i was accessed from
> > multiple threads, the code is *broken*.
> 
> Not necessarily.  If i is a 32-bit number and only one thread is
> doing the writing then the code could be perfectly safe.
> 
> 
> Sean

i don't think so. reading must be still fenced if at least one thread writes to it. walt is correct.



More information about the Digitalmars-d mailing list