NetBSD-Users archive

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

Re: pwrite() and threads



Giles Lean(giles.lean%pobox.com@localhost) said 2010.05.26 23:26:21 +0000:
> POSIX doesn't agree with you, I'm afraid.

Fair enough. I was looking at a UN*X spec that was rather sparse on details.

> > 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?
> 
> You've still got the atomic issue with write().
> 
> So, yeah, either give up on multiple threads/processes
> writing, keep below PIPE_BUF, or lock the file before writing
> is all I can think of at the moment.

There is another option. Have one thread dedicated to writing, have all
other threads pass a message to this thread with the data they wish to have
written to what location. This single thread can then proceed to append to
each file in order without locking issues. As an improvement to parallelism
there could be a small pool of these threads each dedicated to certain
files. 
Avoiding threading safety issues is better than dealing with them.

> Giles
        Wouter


Home | Main Index | Thread Index | Old Index