2 ms·
I 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
by jstimpfle 9y ago
I 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.