Concurrent Haskell

Andre W B Furtado aw@free.elogica.com.br
Mon, 16 Apr 2001 20:36:30 -0300


This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C0C6B4.EADF75A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to create a program that prints interleaved sequences of =
'a's and 'z's, using Haskell Direct (under GHC). I've tryied the =
following:

import Concurrent

main :: IO()
main =3D let loop ch =3D putStr(ch) >> loop ch in
       forkIO (loop "a") >> loop "z"

But this program prints only 'z's, and no 'a's. I was surprised by this, =
since GHC uses preemptive multitasking, not cooperative multitasking. =
Does anyone knows what's going wrong?

Thanks,
Andre W b Furtado

------=_NextPart_000_002A_01C0C6B4.EADF75A0
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 content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to create a program that =
prints=20
interleaved sequences of&nbsp;'a's&nbsp;and 'z's, using Haskell Direct =
(under=20
GHC). I've tryied the following:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import Concurrent</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>main :: IO()<BR>main =3D let loop ch =
=3D putStr(ch)=20
&gt;&gt; loop ch in<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; forkIO (loop =
"a")=20
&gt;&gt; loop "z"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But this program prints only 'z's, and =
no=20
'a's.&nbsp;I was surprised by this, since GHC uses preemptive =
multitasking, not=20
cooperative multitasking. Does anyone knows what's going =
wrong?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Andre W b =
Furtado</FONT></DIV></BODY></HTML>

------=_NextPart_000_002A_01C0C6B4.EADF75A0--