Skip to content
try5.hs 522 B
Newer Older
Yuanle Song's avatar
Yuanle Song committed
-- use default Chan, use shutdown msg to terminate program.
-- let master thread wait for all created threads to finish.
-- well, do that on try 1 as well.

import Control.Concurrent (threadDelay)

import WorkGroup

-- | delay many seconds, then print a msg
printMsg :: Int -> IO ()
printMsg sec = do
  threadDelay $ sec * 1000000
  putStrLn "hehe"

main :: IO ()
main = do
  wg <- newWorkGroup
  forkIOwg wg $ printMsg 1
  forkIOwg wg $ printMsg 2
  forkIOwg wg $ printMsg 3
  forkIOwg wg $ printMsg 4
  joinWorkGroup wg