Compiler optimization breaks multi-threaded code
Kagamin
spam at here.lot
Mon Nov 15 01:09:34 PST 2010
Sean Kelly Wrote:
> > shared uint cnt;
> > void atomicInc ( ) { uint o; while ( !cas( &cnt, o, o + 1 ) ) o = cnt; }
> >
> > is compiled with dmd -O to something like:
> >
> > shared uint cnt;
> > void atomicInc ( ) { while ( !cas( &cnt, cnt, cnt + 1 ) ) { } }
> What a mess. DMD isn't supposed to optimize across asm blocks.
There're no asm blocks in the code. It's a violated contract of shared data access.
More information about the Digitalmars-d
mailing list