3 ms·
> The appropriate uses of mfence are actually much more limited, it's only really needed with special memory types (e.g. write combined) or when you need orderi
by amluto 12y ago
> The appropriate uses of mfence are actually much more limited, it's only really needed with special memory types (e.g. write combined) or when you need ordering on certain non temporal loads and stores (mostly vector instructions) AFAIK.
You may be thinking of sfence here, not mfence.
> In regular code you should never require the hammer of mfence for correct synchronization. You can implement C++11 atomics without it.
That's true, but I think that, in many circumstances, mfence is cheaper than atomic RMW instructions.
EDIT: Maybe I'm wrong. lock addl to the stack is faster than mfence on my laptop, but not that much faster. This is strange, because in most cases you can replace mfence with a locked access to an unrelated memory location. sfence is much faster than either.