Hi
I think that there's a bug in dupChan in Chan.lhs
 
I tried the following program.
 
main = do
 chan <- newChan
 ch <- dupChan chan
 writeChan chan "done"
 x <- readChan chan
 y <- readChan ch
 prnt ("Got "++x ++" "++y)
 
Now if I remember correctly this should print "Got done done".
 
Instead it exits with
C:\Test\test.exe: no threads to run:  infinite loop or deadlock?
 
I looked for the code for dupChan in hslibs and it says

dupChan :: Chan a -> IO (Chan a)
dupChan (Chan _read write) = do
   new_read <- newEmptyMVar
   hole     <- readMVar write
   putMVar new_read hole
   return (Chan new_read write)
 
Shouldn't this instead be
 
dupChan :: Chan a -> IO (Chan a)
dupChan (Chan _read write) = do
   new_read <- newEmptyMVar
   hole     <- readMVar write
   putMVar new_read hole
** putMVar write hole **
   return (Chan new_read write)
 
That's at least what the Concurrent haskell paper says.
 
Hugs 98 seems to have the same bug with its library.
 
Meurig

Reply via email to