News for hackers. Stuff that matters.
Re:Who ordered memory fences on an x86? (2008) by amluto on Friday November 07, 2014 @01:02PM (#8573749)
> 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.

Re:Who ordered memory fences on an x86? (2008) by pkhuong on Friday November 07, 2014 @01:11PM (#8573802)
re sfence: standard x86 memory ordering forbids store/store reordering anyway.
Re:Who ordered memory fences on an x86? (2008) by amluto on Friday November 07, 2014 @02:53PM (#8574335)
sfence is only useful for WC memory and non-temporal stores. I'm not sure what lfence is for other than use in conjuction with rdtsc and possibly IO.