If there are multiple threads writing fixed length data (say 4 byte address) to a single pipe and there is a single reader of that pipe, is it guaranteed that the reader will get bytes in order? In other words, is write()
to a pipe atomic?
Asked
Active
Viewed 3,221 times
1 Answers
7
http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
Atomic/non-atomic: A write is atomic if the whole amount written in one operation is not interleaved with data from any other process. This is useful when there are multiple writers sending data to a single reader. Applications need to know how large a write request can be expected to be performed atomically. This maximum is called {PIPE_BUF}. This volume of IEEE Std 1003.1-2001 does not say whether write requests for more than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or fewer bytes shall be atomic.

David Titarenco
- 32,662
- 13
- 66
- 111
-
Thanks. I saw the man page http://linux.die.net/man/2/write and didn't see anything. – Manish Jan 20 '11 at 04:25
-
Note that the value of `PIPE_BUF` varies significantly between Unix systems. See here for a collation of observed values: http://ar.to/notes/posix#pipe-buf – Arto Bendiken Oct 08 '14 at 00:09