Skip to content

Commit

Permalink
#73, make the parallelN function exception safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Jul 28, 2014
1 parent 0380885 commit c072bcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Changelog for HLint

#73, fix multithreading and exceptions with the API
1.9.2
#68, add --no-summary
1.9.1
Expand Down
7 changes: 4 additions & 3 deletions src/Parallel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Parallel(parallel) where
import System.IO.Unsafe
import GHC.Conc(numCapabilities)
import Control.Concurrent
import Control.Exception
import Control.Monad


Expand All @@ -34,13 +35,13 @@ parallelN xs = do
chan <- newChan
mapM_ (writeChan chan . Just) $ zip ms xs
replicateM_ numCapabilities (writeChan chan Nothing >> forkIO (f chan))
parallel1 $ map takeMVar ms
let throwE x = throw (x :: SomeException)
parallel1 $ map (fmap (either throwE id) . takeMVar) ms
where
f chan = do
v <- readChan chan
case v of
Nothing -> return ()
Just (m,x) -> do
x' <- x
putMVar m x'
putMVar m =<< try x
f chan

0 comments on commit c072bcc

Please sign in to comment.