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 13:50:05 +0000
Wouter Klouwen <dublet%acm.org@localhost> wrote:

> 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.

You would still use locking, only this time you would also need
condition variables to signal to other threads when the copy was
complete.

I think it's simpler to lock a mutex, write to file descriptor and
unlock a mutex when copy is done. If you buffer your data, then
overhead of locking should be negligible.


Home | Main Index | Thread Index | Old Index