Message board for the users of flat assembler.
> Examples and Tutorials > Accurate multi-threaded 64-bit counters on a 32-bit machine
Goto page 1, 2, 3 Next
The most obvious way to solve the problem of atomic 64-bit updates to memory values from multiple CPUs is to use the OS synchronisation functions. They will work, but they can be very expensive.
A much more efficient method is to use cmpxchg8b (available on Pentium and later CPUs).
So without much further ado, here is an example:
macro atomic_64_bit_read address ;thread safe read 64-bit memory location. read edx eax from memory ;ebx and ecx are corrupted mov ebx,eax ;in case of match place back the same value