If you would like to wait on multiple threads, you can use STM like so:
import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception
main = do
tc <- atomically $ newTVar 2
run tc (print (last [1..100000000]))
run tc (print (last [1..110000000]))
print "Waiting...."
atomically $ readTVar tc >>= \x -> if x == 0 then return () else retry
print "OK."
where
run tc f = forkIO (f `finally` atomReplace (\x -> x - 1) tc)
atomReplace fn x = atomically $ readTVar x >>= writeTVar x . fn
Regards
brad
--
www.scoodi.com
Recycle is good: Reuse is better
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe