Sharing in D

Sean Kelly sean at invisibleduck.org
Fri Aug 1 11:47:31 PDT 2008


== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Sean Kelly wrote:
> > == Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> >> 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.
> If you've got only one thread, why is it shared ? If it is shared,
> there's the possibility of multiple threads, and so the code is wrong
> wrong wrong.

Only one writer, multiple readers.  But this is assuming the INC is issued
to the CPU rather than the compiler deciding to just hold onto the value
in a register or something.  ie. I think "shared" implies more than fences,
yes?  It's also an indication to the compiler than certain optimizations
may not be performed, roughly similar to 'volatile' in D 1.0.


Sean



More information about the Digitalmars-d mailing list