NetBSD-Users archive

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

pwrite() and threads



Hi, I'm writing a small logging library that can be used concurrently by
multiple threads. Each thread has its own log buffer and when the
buffer gets full it is flushed to file on disk, and/or syslog socket.

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.

For example, two threads need to flush their log buffer to the same
file:

thread1 needs to write 2048 bytes to /var/log/out.log

thread2 needs to write 2048 bytes to /var/log/out.log

If both threads call pwrite() at the same time, does pwrite() guarantee
that all 2048 bytes from a thread will be written atomically?

Or is it likely that large writes from multiple threads will be broken
down into smaller atomic units and intermingled in the log file?


Home | Main Index | Thread Index | Old Index