NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pwrite() and threads



On Wed, 26 May 2010 12:37:55 +0000
Wouter Klouwen <dublet%acm.org@localhost> wrote:

> 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

Yeah I think this is what I was looking for, if you open a file with
O_APPEND flag, the kernel will atomically position file pointer to the
end of file before each write().

There is a constant PIPE_BUF which tells how much data can be written
atomically to a pipe or fifo. I'm not sure if the same applies to
regular files.


Home | Main Index | Thread Index | Old Index