2 ms·
Isn’t one of the more important points of POSIX that reading sequentially results in an atomic copy ? As long as you keep the file handle open and the fs suppor
by candiodari 9y ago
Isn’t one of the more important points of POSIX that reading sequentially results in an atomic copy ? As long as you keep the file handle open and the fs supports it.
- jstimpfle 9y agoI don't know which point you mean, but that would mean that any writer would be blocked indefinitely by any other reader. That amounts to a read lock. You don't get a read lock just by opening a file for reading. You can test that with a simple shell script { echo line1 echo line2 } > test.txt { read line echo got "$line" sleep 2 read line echo got "$line" } < test.txt & # concurrent write sleep 1; { echo line2 echo line1 } > test.txt wait This script does a concurrent write while the reader is in the "sleep 2" phase. The output should be got line1 got line1 (given that the sleeps do the expected thing). POSIX might contain something that requires aligned blocks of 512 bytes or so to be read or written atomically. But only if you do that in a single system call, of course.