Deadlock when using Control.Concurrent.Chan

Ben Franksen ben.franksen at online.de
Sat Feb 28 14:15:42 EST 2009


Ben Franksen wrote:
> import Control.Concurrent
> import Control.Concurrent.Chan
> import Control.Monad
> 
> test = do
>   c <- newChan
>   forkIO $ forever $ do
>     i <- readChan c
>     print i
>   writeChan c 1
>   threadDelay 1000000
>   isEmptyChan c >>= print
> 
> Test session:
> 
> ben at sarun[1]: .../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.
> *Main> test
> 1

Correction: This is not a deadlock, technically speaking.

I still think isEmptyChan should not block indefinitely only because some
reader is blocked on an empty chan.

Cheers
Ben



More information about the Libraries mailing list