bug in dupChan
Meurig Sage
meurig@dcs.gla.ac.uk
Wed, 24 Jan 2001 18:07:00 -0000
This is a multi-part message in MIME format.
------=_NextPart_000_02DA_01C08630.72DDBAE0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi=20
I think that there's a bug in dupChan in Chan.lhs
I tried the following program.=20
main =3D 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=20
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) =3D do
new_read <- newEmptyMVar
hole <- readMVar write
putMVar new_read hole
return (Chan new_read write)
Shouldn't this instead be=20
dupChan :: Chan a -> IO (Chan a)
dupChan (Chan _read write) =3D 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
------=_NextPart_000_02DA_01C08630.72DDBAE0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I think that there's a bug in dupChan =
in=20
Chan.lhs</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I tried the following program. =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
size=3D2></FONT> </DIV><FONT face=3DArial size=3D2>main =3D =
do<BR> chan <-=20
newChan<BR> ch <- dupChan chan<BR> writeChan chan =
"done"<BR> x=20
<- readChan chan<BR> y <- readChan ch<BR> prnt ("Got =
"++x ++"=20
"++y)</FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Now if I remember correctly this should =
print "Got=20
done done".</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Instead it exits with </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>C:\Test\test.exe: no threads to =
run: infinite=20
loop or deadlock?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I looked for the code for dupChan in =
hslibs and it=20
says</FONT></DIV><FONT face=3DArial size=3D2>
<DIV><BR>dupChan :: Chan a -> IO (Chan a)<BR>dupChan (Chan _read =
write) =3D=20
do<BR> new_read <- newEmptyMVar<BR> =20
hole <- readMVar write<BR> =
putMVar=20
new_read hole<BR> return (Chan new_read write)</DIV>
<DIV> </DIV>
<DIV>Shouldn't this instead be </DIV>
<DIV></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>dupChan :: Chan a -> IO (Chan =
a)<BR>dupChan=20
(Chan _read write) =3D do<BR> new_read <-=20
newEmptyMVar<BR> hole <- readMVar =
write<BR> putMVar new_read hole</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>** putMVar write hole =
**<BR> =20
return (Chan new_read write)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>That's at least what the Concurrent =
haskell paper=20
says.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Hugs 98 seems to have the same bug with =
its=20
library.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Meurig</FONT></DIV></BODY></HTML>
------=_NextPart_000_02DA_01C08630.72DDBAE0--