Last active
December 27, 2015 15:39
-
-
Save AlexanderAA/7349033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Fork ( | |
main | |
) where | |
import Control.Concurrent (forkIO, ThreadId, threadDelay) | |
import Control.Concurrent.STM | |
import Control.Monad | |
import Control.Monad.IO.Class (liftIO) | |
import System.Random | |
second :: Int | |
second = 1000000 --microseconds | |
action :: String -> IO () | |
action message = do | |
delay <- getStdRandom (randomR (0, 5*second)) | |
threadDelay delay | |
putStrLn $ (show delay) ++ " * " ++ message | |
z1 messages = forkIO ((void . (mapM (forkIO . action)) . (take 10000)) messages) | |
z2 = (mapM (forkIO . action)) . (take 10000) | |
main = do | |
let messages = map (("M" ++) . show) [1..] | |
p <- (z2 messages) | |
print p | |
--threadDelay (3*second) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment