[Haskell-cafe] Parallel executing of actions
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Mon Apr 16 00:52:04 EDT 2007
Joel Reymont wrote:
>
> On Apr 15, 2007, at 8:23 PM, Spencer Janssen wrote:
>
> >parSequence_ xs = do
> > m <- newEmptyMVar
> > mapM_ (\x -> forkIO x >> putMVar m ()) xs
should be
mapM_ (\x -> forkIO (x >> putMVar m ())) xs
> > replicateM_ (length xs) (takeMVar m)
>
> mapM_ above spawns (length xs) threads blocking on a single "lock",
> right?
yes.
> replicateM_ then makes sure that the lock is "unlocked" as many times
> as threads spawned, right?
right.
> Since all the threads block on a single MVar how do they run in
> parallel?
The idea is that before the threads block on the MVar, they run their
action x to completion.
Bertram
More information about the Haskell-Cafe
mailing list