News for hackers. Stuff that matters.
Re:Things Unix can do atomically (2010) by throwaway76543 on Monday May 30, 2016 @08:16PM (#11803898)
msync() with MS_INVALIDATE doesn't belong on this list. It has nothing to do with atomic memory access. msync() is used when flushing a mapped file to durable storage. I very often see this mistake of conflating flushing caches with atomic access of memory. What's committed to durable storage has nothing to do with what multiple processes will see when mapping a file.

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.

Re:Things Unix can do atomically (2010) by gpderetta on Tuesday May 31, 2016 @06:24AM (#11805722)
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).
Re:Things Unix can do atomically (2010) by gpderetta on Tuesday May 31, 2016 @06:50AM (#11805788)
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 ...