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/





_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to