user2059893
user2059893

Reputation: 447

Is msync atomic?

When using mmap/msync/munmap, are the read/write atomic? (assuming the disk will finish any pending writes when powering down)

Upvotes: 0

Views: 464

Answers (1)

DigitalRoss
DigitalRoss

Reputation: 146093

Operations that involve multiple pages or multiple disk sectors are never precisely atomic.

It might be more useful to investigate coherency between two specific things.

For example, between two programs or threads that are both mmap(2)-ing the same file, they are already coherent and msync(2) is unrelated to this. All msync does is cause the kernel to write modified pages to the underlying storage system ... it is not necessary or helpful with respect to other readers and writers on the same system also using mmap().

If you want to use a different facility (shared storage or non-mmap I/O) and synchronize access, you will need a real semaphore or interlock. I don't think msync() can be useful. To give you more help we would need to know more about what you are trying to synchronize.

Upvotes: 2

Related Questions