The man page for write
states:
POSIX requires that a read(2) which can be proved to occur after a
write() has returned returns the new data. Note that not all filesys‐
tems are POSIX conforming.
What exactly does "proved to occur" mean here? If process 1 write
s data to a file descriptor on an ext4 filesystem, and process 2 calls read
on that same file immediately after the write
returns, does that mean that process 2 is guaranteed to get the data written by process 1?
The POSIX wording is marginally more clear, at least on the separate process part:
If a read() of file data can be proven (by any means) to occur after a write() of the data, it must reflect that write(), even if the calls are made by different processes.
The proof basically just means that you can show the order is not arbitrary (due to a race condition).
If process 2 happens to call read
immediately after the write occurs, then it's not technically guaranteed to get the data.
However, if process 1 wrote something and then toggled a mutex, sent a signal, or performed any kind of operation that process 2 may directly or indirectly have observed before reading (even if it's just observing a change in filesize caused by the write itself), then the read
is required to return that written data.
I don't know if/how the distinction is leveraged in practice, but it does for example mean that the OS can merge two sequential writes without having to take care to provide an intermediate result to anyone who just happened to read in the middle of them.