Talk:IPC via named pipe: Difference between revisions

 
(3 intermediate revisions by 3 users not shown)
Line 4:
: <s>Actually I don't think <code>O_WRONLY|O_NONBLOCK</code> on a fifo will ever succeed on a POSIX system.</s>(unless there is already a reader) On Linux, you can <code>O_RDWR</code> open a fifo, and it will not block (because the program itself is the reader then), but then you can't <code>select</code> it for write readiness because it ''always'' returns immediately with success. Luckily here one thread blocking on open will not hold up the entire process, so it's relatively easy to deal with. --[[User:Ledrug|Ledrug]] 11:44, 30 September 2011 (UTC)
 
:: You only want to have one end of each named pipe open in the process; using <code>O_RDWR</code> is opening both ends, and that's semantically wrong anyway (irrespective of whether or not it “works” with select()). It's irritating that O_NONBLOCK doesn't work for the pipe writer — POSIX [http://pubs.opengroup.org/onlinepubs/009604599/functions/open.html specifies that behavior] for reasons that are unclear to me, which scuppers the whole plan of using select() to wait for a reader, and the rationale doesn't go into enough depth — but at least it means that we can handle it with polling to give the right overall effect. (Sockets are nicer.) –[[User:Dkf|Donal Fellows]] 12:23, 3 October 2011 (UTC)
=== OpenBSD blocks the entire process ===
 
::: O_RDWR is semantically wrong, but POSIX specifically left it undefined instead of an error, which might be an intentional shortcut left to individual OS implementations. O_NONBLOCK|O_WRONLY behavior, as I vaguely understand it, has something to do with the pipe buffer management, though I'm very unsure about it. --[[User:Ledrug|Ledrug]] 00:43, 4 October 2011 (UTC)
 
=== OpenBSD blocks the entire process ===
<lang ruby>$ irb -rthread
irb(main):001:0> q = Queue.new; Thread.new {q << open("out", "w")}
Line 18 ⟶ 22:
Some interpreters, like Ruby [[MRI]] 1.8.x, have "green threads". These interpreters might also use non-blocking IO, so they might block the entire process when opening "out" with any OS. --[[User:Kernigh|Kernigh]] 04:21, 2 October 2011 (UTC)
: Eh so on OpenBSD opening a fifo for readonly also blocks whole process? If so, what's the behavoir of <code>read()</code> or <code>select()</code>? --[[User:Ledrug|Ledrug]] 23:23, 2 October 2011 (UTC)
:: Yes, <code>open("in", O_RDONLY)</code> also blocks whole process. Other functions like read(), usleep(), poll() and select() seem to block only current thread. --[[User:Kernigh|Kernigh]] 01:05, 3 October 2011 (UTC)
::: Good then. If <code>read()</code> would have also blocked entire process, reading on "in" pipe could have been a serious problem in case of a slow writer because of pipe buffer. As it stands, I guess it's not a problem. --[[User:Ledrug|Ledrug]] 01:19, 3 October 2011 (UTC)
Anonymous user