This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with named pipes


On 1/8/2016 3:50 PM, Corinna Vinschen wrote:
> On Dec 25 16:39, Ken Brown wrote:
>> I've noticed a difference between Cygwin and Linux involving named pipes.  I
>> don't know if this a bug or simply a difference.
>>
>> Consider the following two scripts:
>>
>> $ cat fifo1.sh
>> #!/bin/sh
>> set -x
>> rm -f foo
>> mkfifo foo
>> exec 7>foo
>> echo blah > foo
>>
>> $ cat fifo2.sh
>> #!/bin/sh
>> set -x
>> read bar < foo
>> echo $bar
>>
>> I run fifo1.sh in Terminal 1 and get the following on both Cygwin and Linux:
>>
>> [Terminal 1]
>> $ ./fifo1.sh
>> + rm -f foo
>> + mkfifo foo
>> + exec
>>
>> The call to echo in the next line blocks, because foo has not yet been
>> opened for reading.  Now I run fifo2.sh in Terminal 2.  On Linux, the "read"
>> in fifo2.sh unblocks fifo1.sh, and I see the following:
>>
>> [Terminal 1, Linux]
>> $ ./fifo1.sh
>> + rm -f foo
>> + mkfifo foo
>> + exec
>> + echo blah
>>
>> [Terminal 2, Linux]
>> $ ./fifo2.sh
>> + read bar
>> + echo blah
>> blah
>>
>> On Cygwin, however, Terminal 1 remains blocked, and Terminal 2 is blocked
>> when it tries to read:
>>
>> [Terminal 2, Cygwin]
>> $ ./fifo2.sh
>> + read bar
>>
>> The problem disappears if I remove the line "exec 7>foo" from fifo1.sh.  The
>> problem also disappears if I leave that line in, but change the last line to
>> "echo blah >&7".
> 
> Very tricky problem.  The FIFO code falls over its own feet trying to
> handle more than one writer (exec 7> is the first, echo blah is the
> second writer).  Sigh.  This code needs a thorough rewrite...

Hi Corinna,

I'm coming back to this thread after three years.  I'd be willing to put in some 
time working on this, if you could point me in the right direction.  Do you have 
ideas about what a rewrite of the FIFO code might look like?

The one idea that I had was that a reader could open several instances of the 
Windows named pipe, allowing several writers to connect to it simultaneously.  I 
think that would solve the particular problem I reported (and the similar 
problem cited by Houder up-thread).  But it would just be a band-aid, and Cygwin 
FIFOs still wouldn't be POSIX compliant.

Ken

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]