Deadlock when using Control.Concurrent.Chan
ben.franksen at online.de
Sat Feb 28 09:14:01 EST 2009
This code demonstrates the problem:
test = do
c <- newChan
forkIO $ forever $ do
i <- readChan c
writeChan c 1
isEmptyChan c >>= print
ben at sarun: .../hca/current > ghci Bug5.hs
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( Bug5.hs, interpreted )
Ok, modules loaded: Main.
The program hangs here. This is a deadlock caused by the calls to
isEmptyChan and readChan both waiting on the same MVar, as a quick look at
the sources reveals. I don't have an immediate fix but is shouldn't be too
hard to find one. I can try to, if it is consensus that this is a bug.
Incidentally, if I replace Chan with TChan (and wrap all xxxTChan calls in
an atomically), then this code terminates just fine.
More information about the Libraries