Created
January 31, 2012 01:32
-
-
Save mwotton/1708089 to your computer and use it in GitHub Desktop.
This file contains 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
children :: MVar [MVar ()] | |
children = unsafePerformIO (newMVar []) | |
waitForChildren :: IO () | |
waitForChildren = do | |
cs <- takeMVar children | |
case cs of | |
[] -> return () | |
m:ms -> do | |
putMVar children ms | |
takeMVar m | |
waitForChildren | |
forkChild :: IO () -> IO ThreadId | |
forkChild io = do | |
mvar <- newEmptyMVar | |
childs <- takeMVar children | |
putMVar children (mvar:childs) | |
forkIO (io `finally` putMVar mvar ()) | |
main = | |
later waitForChildren $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment