Tricky! In a 32-bit environment the stores will be translated as 32-bit stores. But the CPU will apply write-combining to the stores.
The truly atomic operation from the hardware point of view is a 64-bit store, as the FSB is 64-bit wide. But I don't think there are any memory controllers that actually allow interruption of a burst cycle, which stores 8 consecutive 64-bit words (one cache line).
I guess to be absolutely safe in a 32-bit environment, you would have to use an FPU store. The best way to force a compiler to use one is
- Code: Select all
void AtomicStore(double *source, double *destination)
{ *destination = *source; }
and then call it with the source a pointer to the u64 you want to store, casted to (doouble *) to avoid compiler complaints.
Btw, another way to do lockless hashing is simply make sure the lock is distributed over the two (or more) atomic stores. With a 32-bit signature, you could put 16 bits of it in each of the two words, and there would only be a 1 in 64K probability of a corrupted entry to bhave a valid signature.