simpler way to do this
Remove old code that can be trivially implemented using async in a much nicer way (that is async exception safe). I've audited all forkOS calls (except for ones in the assistant), and this was the last remaining one that is not async exception safe. The rest look ok to me.
This commit is contained in:
parent
074260f036
commit
660d8d3a87
3 changed files with 7 additions and 37 deletions
|
@ -1,34 +0,0 @@
|
|||
{- parallel processing via threads
|
||||
-
|
||||
- Copyright 2012 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
||||
module Utility.Parallel (inParallel) where
|
||||
|
||||
import Common
|
||||
|
||||
import Control.Concurrent
|
||||
|
||||
{- Runs an action in parallel with a set of values, in a set of threads.
|
||||
- In order for the actions to truely run in parallel, requires GHC's
|
||||
- threaded runtime,
|
||||
-
|
||||
- Returns the values partitioned into ones with which the action succeeded,
|
||||
- and ones with which it failed. -}
|
||||
inParallel :: (v -> IO Bool) -> [v] -> IO ([v], [v])
|
||||
inParallel a l = do
|
||||
mvars <- mapM thread l
|
||||
statuses <- mapM takeMVar mvars
|
||||
return $ reduce $ partition snd $ zip l statuses
|
||||
where
|
||||
reduce (x,y) = (map fst x, map fst y)
|
||||
thread v = do
|
||||
mvar <- newEmptyMVar
|
||||
_ <- forkIO $ do
|
||||
r <- try (a v) :: IO (Either SomeException Bool)
|
||||
case r of
|
||||
Left _ -> putMVar mvar False
|
||||
Right b -> putMVar mvar b
|
||||
return mvar
|
Loading…
Add table
Add a link
Reference in a new issue