
16 Apr
2007
16 Apr
'07
12:52 a.m.
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