There is one question on SO which seems like a serious problem for atomic
ops.
http://stackoverflow.com/questions/4165149/compiler-optimization-breaks-
multi-threaded-code
in short:
shared uint cnt;
void atomicInc ( ) { uint o; while ( !cas( &cnt, o, o + 1 ) ) o = cnt; }
is compiled with
Michal Minich Wrote:
> There is one question on SO which seems like a serious problem for atomic
> ops.
>
> http://stackoverflow.com/questions/4165149/compiler-optimization-breaks-
> multi-threaded-code
>
> in short:
>
> shared uint cnt;
> void atomicInc ( ) { ui
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
Kagamin wrote:
> 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
Am 16.11.2010 18:09, schrieb Sean Kelly:
cas() contains an asm block. Though I guess in this case the compiler
isn't actually optimizing across it. Does atomic!"+="(&cnt, 1) work
correctly? I know the issue with shared would still have to be fixed,
but that code uses asm for the load as well, so
stephan Wrote:
> Am 16.11.2010 18:09, schrieb Sean Kelly:
> > cas() contains an asm block. Though I guess in this case the compiler
> > isn't actually optimizing across it. Does atomic!"+="(&cnt, 1) work
> > correctly? I know the issue with shared would still have to be fixed,
> > but that code u
atomicOp uses a CAS loop for the RMW operations.
Ignore my comment. I should have looked at the code in core.atomic
before commenting. I just had one test case with atomicOp!("+=") that
worked, and assumed that atomicOp!("+=") was implemented with "lock xadd".
I'm thinking of exposing atomicS