Concurrent Haskell (Ops...)
[I mean "CONCURRENT Haskell" rather than "Haskell DIRECT" in the last email. Sorry.] ------- 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 = let loop ch = 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
Andre W B Furtado writes: : | import Concurrent | | main :: IO() | main = let loop ch = 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? By my count, this is now a TAQ (thrice asked question). :-) http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg01599.html
About the program below, someone (I think Simon Marlow) said that if I run it for long enough, I'll see "a"s rather than "b"s. I would like to know for how long I will have to wait, since 2 hours were not enough to see it switching from "b"s to "a"s.
main = forkIO a >> b where a = putStrLn "a" >> a b = putStrLn "b" >> b
Thanks, Andre Furtado ----- Original Message ----- From: Tom Pledger <Tom.Pledger@peace.com> To: <haskell@haskell.org> Sent: Tuesday, April 17, 2001 12:24 AM Subject: Concurrent Haskell (Ops...)
Andre W B Furtado writes: : | import Concurrent | | main :: IO() | main = let loop ch = 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?
By my count, this is now a TAQ (thrice asked question). :-)
http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg01599.html
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (2)
-
Andre W B Furtado -
Tom Pledger