unix pipe multiple writers

2019-02-17 01:15发布

问题:

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?

回答1:

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.



标签: unix ipc pipe