[Haskell-cafe] Parallel executing of actions

Joel Reymont joelr1 at gmail.com
Sun Apr 15 19:16:07 EDT 2007


On Apr 15, 2007, at 8:23 PM, Spencer Janssen wrote:

> parSequence_ xs = do
>     m <- newEmptyMVar
>     mapM_ (\x -> forkIO x >> putMVar m ()) xs
>     replicateM_ (length xs) (takeMVar m)

mapM_ above spawns (length xs) threads blocking on a single "lock",  
right?

replicateM_ then makes sure that the lock is "unlocked" as many times  
as threads spawned, right?

Since all the threads block on a single MVar how do they run in  
parallel?

	Thanks, Joel

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list