NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pwrite() and threads
Sad Clouds(cryintothebluesky%googlemail.com@localhost) said 2010.05.26 12:19:58
+0000:
> I'm a bit confused about the semantics of pwrite(2). As far as I
> understand pwrite() does atomic lseek-and-write. However I'm not sure
> what happens when data to be written is larger than the disk block size.
Depends. As far as I can tell, pwrite itself should be atomic, regardless
how big the data buffer is.
> If both threads call pwrite() at the same time, does pwrite() guarantee
> that all 2048 bytes from a thread will be written atomically?
Yes, but if you write at a specific offset, you might have a small problem.
Say two threads simultaneously want to write, they both calculate the offset
and then write to that offset. The end result? Possibly one entry lost as
one writes over the other due to invalidated offsets.
It seems to me that you need to lock before you calculate the offset anyway.
If you are logging, why are you not opening these files in "a" mode and just
using write() anyway?
--Wouter
Home |
Main Index |
Thread Index |
Old Index