>By the way, is the blocking behavior of fifos part of POSIX ?
It's Complicated (tm).
Roughly yes. The important parts, i.e. how open(fifo, O_WRONLY) and
write() should behave when there's no reader, are specified by POSIX, so
the behaviour is perfectly safe. For our use case of using fifos as
synchronization points, you can rest assured that things will work.
The problematic parts of fifos are what happens when there are
multiple readers (which is a programming error anyway), and what happens
to the reader when the last writer closes and another reopens. The
latter
is a real question that I (and djb before me) have encountered, and the
behaviour is different on many OSes and cannot be relied on. So be
careful
if you play with fifos; when I need fifos, as in the ftrigr library, I
always open the fifo for writing as well as for reading (and do nothing
with the writing fd), guaranteeing that a reader always has at least one
writer, in which case everything happens portably.
(Another issue is what exactly happens when the last writer closes and
the reader is using an asynchronous event loop. On some systems the
reader
gets POLLIN, on others POLLHUP, and on others POLLIN|POLLHUP. Making
sure
a reader always has a writer also avoids that problem.)
--
Laurent
Received on Sat Jan 28 2017 - 10:47:40 UTC