Is core.internal.atomic.atomicFetchAdd implementation really lock free?

rikki cattermole rikki at cattermole.co.nz
Sun Dec 4 01:56:02 UTC 2022


On 04/12/2022 2:51 PM, max haughton wrote:
> Memory ordering is literally why modern atomic operations exist. That's 
> why there's a lock prefix on the instruction in X86 - it doesn't just 
> say "do this in one go" it says "do this in one go *and* maintain this 
> memory ordering for the other threads".

Also worth remembering that at some point somebody has to do 
synchronization to make atomics work.

It doesn't matter if its in user code, or in microcode. It has to exist 
some place.

If it doesn't, you continue to have different cores with different 
values for a chunk of memory. This is something you do not want to 
encounter and it makes you lose hair (from experience).


More information about the Digitalmars-d mailing list