Are write() calls guaranteed atomic?

Matthew Hagerty matthew at mundomateo.com
Mon Jun 2 08:07:22 PDT 2003


Greetings,

I'm writing a server that receives data via a named pipe (FIFO) and will
always have more than one other process sending data to it, and I'm
concerned with preventing data multiplexing.  The data coming in will be
lines of text delimited with a newline, but the processes writing the data
have no knowledge of the FIFO, they simply think they are writing to a
file.  This being the case, the processes writing the data give no regard
to PIPE_BUF and may send data in longer lengths (but probably never longer
than 2K to 4K.)

Will the kernel ensure that the data write() will be delivered to the FIFO
atomically even if the data is larger than PIPE_BUF, such that two or more
successive read() calls will retrieve the data in order?

If this is the case, is this specific to FreeBSD, or is this functionality
defined as a POSIX standard and generally portable?

Any insight would be greatly appreciated.

Thanks,
Matthew


More information about the freebsd-hackers mailing list