module Concur(main) whereimport Control.Concurrentimport System.IO-- Use ::Int to avoid using Integer anywhere since-- the can change the timing on different platforms-- (32 vs 64 bit, with or without GMP).delay :: Int -> IO ()delay i = loop (i*100) `seq` return ()loop :: Int -> Intloop i = if i == (0::Int) then (0::Int) else loop (i - (1::Int))showId :: String -> IO ()showId s = do i <- myThreadId putStrLn $ "thread " ++ show i ++ ": " ++ show srun :: Int -> String -> IO ()run i s = if i == (0::Int) then return () else do delay (10000::Int) putStr s hFlush stdout run (i - (1::Int)) sxrun :: Int -> String -> IO ()xrun i s = do delay i showId s delay (2000::Int) run (1000::Int) smain :: IO ()main = do putStrLn "start" forkIO $ xrun (1000::Int) "b" forkIO $ xrun (2000::Int) "c" xrun (0::Int) "a" delay (100000::Int) putStrLn "\ndone"