I'm slightly confused: what's the difference between memory fence and synchronization?
bpr
@MangoSister, memory fences just enforce the ordering between read and write operations. Synchronization is ordering between threads. That said, synchronization is often treated as some form of memory fence.
MangoSister
@bpr, so is it correct that the purpose of memory fence is to guarantee the ordering of reads and writes within the thread that uses it (otherwise reads and writes may be out-of-order for optimization)?
bpr
@MangoSister, yes. Correct ordering can be required as either the order of memory operations is required due to the memory operations in another thread. Or the ordering can be required for a single thread's execution to be correct.
I'm slightly confused: what's the difference between memory fence and synchronization?
@MangoSister, memory fences just enforce the ordering between read and write operations. Synchronization is ordering between threads. That said, synchronization is often treated as some form of memory fence.
@bpr, so is it correct that the purpose of memory fence is to guarantee the ordering of reads and writes within the thread that uses it (otherwise reads and writes may be out-of-order for optimization)?
@MangoSister, yes. Correct ordering can be required as either the order of memory operations is required due to the memory operations in another thread. Or the ordering can be required for a single thread's execution to be correct.