Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix pipe multiple writers

Tags:

unix

pipe

ipc

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?

like image 962
Manish Avatar asked Jan 20 '11 04:01

Manish


1 Answers

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.

like image 159
David Titarenco Avatar answered Sep 28 '22 11:09

David Titarenco