[Haskell-cafe] writing to a fifo when the reader stops reading

briand at aracnet.com briand at aracnet.com
Sun Mar 13 08:16:11 CET 2011

Hi all,

here's the code:

writer =
  do threadDelay 100000
     threadWaitWrite fd
     fdWrite fd ((show x) ++ "\n")
     writer fd (x+1)

pretty simple, it just keeps writing.  What happens though is that,
eventually, the reader goes away, i.e. "closes" the fifo.

When that happens I get:

ghc: fdWriteBuf: resource vanished (Broken pipe)

which make sense, sort of.  I write a value, let's say 10, and the
reader reads it.  It's the last value so it "closes" the fifo.

Now there's nothing reading, so when I get to threadWaitWrite, I would
expect the program to wait, just as it does when it starts up and there
is no reader.

looking for some guidance.

Thank you,


More information about the Haskell-Cafe mailing list