Right. Msync is an ordering barrier. Barriers go hand in hand with atomic operations, but they are really about visibility, not atomicity.
Re:Things Unix can do atomically (2010)
by prodigal_erik on Monday May 30, 2016 @08:51PM
(#11803994)
I haven't tested but I would expect MS_INVALIDATE on a large buffer to be much faster than filling it a word at a time with __sync_val_compare_and_swap (each causing its own bus transaction).
MS_INVALIDATE is likely a no-op on any modernish Unix, including Linux. It is there to accommodate old systems with non-coherent mapped files and page caches or even multiple mappings of the same file.
Re:Things Unix can do atomically (2010)
by throwaway76543 on Monday May 30, 2016 @10:39PM
(#11804244)
msync() doesn't fill buffers at all. It has no function in the operation you've described.
Even if it did, it's not atomic ...
All that's needed is the initial mmap to share a memory segment, then to use atomic operations like CMPXCHG -- the x86 building block the later mentioned gcc atomic macros leverage.