Messages in this thread | ![/](/images/icornerl.gif) | | Date | Thu, 28 Aug 2003 13:18:23 +0100 | From | Jamie Lokier <> | Subject | Re: Lockless file reading |
| |
Nagendra Singh Tomar wrote: > > Or what about: write("12"), fsync(), write("12")? Is it still possible > > for read() to return "1x1x"? > > Th read will still read both "12"s from the cache (in very high possibility).
That is a terrible assumption.
On all the Linux architures, even single CPUs, with no fancy memory ordering, even 386, Pentiums etc., it is possible for read() to return "1x1x".
Like this: the write() is preempted (see CONFIG_PREEMPT) after writing one "1" byte, the read() runs, reads "1x" and is then preempted back to the writer, which writes "2", calls fsync(), writes "1" and is then preempted back to the reader, which continues and reads its second "1x".
Interrupts caused by network packets arriving at just the wrong moment can trigger that sort of thing.
> Even if the page caches are stolen (due to mem shortage) the kernel > file cachecing will ensure that you get consistent data.
The kernel does not provide synchronisation between read() and write() data transfers, and it does not always use atomic 32-bit reads and writes either.
-- Jamie - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| ![\](/images/icornerr.gif) |