www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Compiler optimization breaks multi-threaded code

reply Michal Minich <michal.minich gmail.com> writes:
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 compile with dmd -O to something like:

shared uint cnt;
void atomicInc  ( ) { while ( !cas( &cnt, cnt, cnt + 1 ) ) { } }

see the web page for details.
Nov 14 2010
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday 14 November 2010 01:04:46 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  ( ) { uint o; while ( !cas( &cnt, o, o + 1 ) ) o = cnt; }
 
 is compile with dmd -O to something like:
 
 shared uint cnt;
 void atomicInc  ( ) { while ( !cas( &cnt, cnt, cnt + 1 ) ) { } }
 
 see the web page for details.
Please repost this to the D list and/or create bug report: http://d.puremagic.com/issues/enter_bug.cgi?product=D The Bugs list is not for posting to. It's for the bug tracker to send updates to. You sign up for it if you want to receive those updates, not to post information on bugs. - Jonathan M Davis
Nov 14 2010