I have found lock inc addr
but that doesn't keep a copy of the stored value around and even a read immediately after it in the same thread could come after a competing write.
The best solution I have found is a load
/inc
/cas
loop.
I have found lock inc addr
but that doesn't keep a copy of the stored value around and even a read immediately after it in the same thread could come after a competing write.
The best solution I have found is a load
/inc
/cas
loop.
see atomic_impl.h for more x86/x86_64 atomic primitives and usage.
This is even simpler:
asm
Lock inc dword ptr J;
end;
where J is your integer to be thread-safely incremented.