packages feed

threadmanager 0.1.3 → 0.1.7

raw patch · 5 files changed

Files

+ README.md view
@@ -0,0 +1,9 @@+*This package is useful, but deprecated. In new code, please use [threads][1]+instead.*++A simple thread management API inspired by the one in [chapter 24][2] of+[Real World Haskell][3].++[1]: http://hackage.haskell.org/package/threads+[2]: http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html+[3]: http://book.realworldhaskell.org/
+ Setup.hs view
@@ -0,0 +1,6 @@+module Main (main) where++import Distribution.Simple (defaultMain)++main :: IO ()+main = defaultMain
− Setup.lhs
@@ -1,8 +0,0 @@-#! /usr/bin/env runhaskell--> module Main (main) where->-> import Distribution.Simple (defaultMain)->-> main :: IO ()-> main = defaultMain
src/Control/Concurrent/ThreadManager.hs view
@@ -1,11 +1,8 @@-{-|-  A simple thread management API inspired by the one in chapter-  24 of /Real World Haskell/.--  See <http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html>.--  Intended to be imported qualified (suggestion: TM).- -}+-- | Intended to be imported qualified, as in+--+-- @+-- import qualified Control.Concurrent.ThreadManager as TM+-- @  module Control.Concurrent.ThreadManager   ( ThreadManager@@ -15,9 +12,9 @@   ) where  import Control.Concurrent      (ThreadId, forkIO)-import Control.Concurrent.MVar (MVar, modifyMVar, newEmptyMVar, newMVar, putMVar, takeMVar, tryTakeMVar)+import Control.Concurrent.MVar (MVar, modifyMVar, newEmptyMVar, newMVar, putMVar, takeMVar, tryTakeMVar, readMVar) import Control.Exception       (SomeException, try)-import Control.Monad           (join, replicateM)+import Control.Monad           (join, replicateM, when) import qualified Data.Map as M  data ThreadStatus =@@ -70,7 +67,15 @@  -- | Block until all managed threads terminate. waitForAll :: ThreadManager -> IO ()-waitForAll (TM tm) =-    modifyMVar tm elems >>= mapM_ takeMVar+waitForAll tm@(TM tmMvar) = do+    threadMap <- readMVar tmMvar+    let threads = M.keys threadMap+    statuses <- mapM (getStatus tm) threads+    _ <- mapM (waitFor tm) threads+    Control.Monad.when (foldr checkStatus False statuses) $+        waitForAll tm   where-    elems m = return (M.empty, M.elems m)+    checkStatus :: Maybe ThreadStatus -> Bool -> Bool+    checkStatus _ True = True+    checkStatus (Just Running) False = True+    checkStatus _ False = False
threadmanager.cabal view
@@ -1,34 +1,50 @@-name:    threadmanager-version: 0.1.3+name:         threadmanager+version:      0.1.7+category:     Concurrency -category: Concurrency+author:       _Real World Haskell_, http://www.realworldhaskell.org/+maintainer:   Brian Lewis <brian@lorf.org> -synopsis: Simple thread management+license:      BSD3+license-file: LICENSE +synopsis:     (deprecated in favor of 'threads') Simple thread management description:-    A simple thread management API inspired by the one in chapter 24 of /Real World Haskell/.-    .-    See <http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html>.+  This package is useful, but deprecated. In new code, please use+  <http://hackage.haskell.org/package/threads threads> instead.+  .+  A simple thread management API inspired by the one in+  <http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html chapter 24 of Real World Haskell>. -author:     _Real World Haskell_, http://www.realworldhaskell.org/-maintainer: Brian Lewis <brian@lorf.org>, Ian Taylor <ian@lorf.org>+cabal-version: >= 1.10+build-type:    Simple -license:      BSD3-license-file: LICENSE+-------------------------------------------------------------------------------- -homepage: http://github.com/bsl/threadmanager+extra-source-files:+  README.md -cabal-version: >= 1.6-build-type:    Simple+--------------------------------------------------------------------------------  library-    hs-source-dirs:  src-    exposed-modules: Control.Concurrent.ThreadManager-    build-depends:   base == 4.*, containers >= 0.2 && < 0.4-    ghc-options:     -Wall-    if impl(ghc >= 6.8)-        ghc-options: -fwarn-tabs+  default-language: Haskell2010 +  ghc-options: -Wall -O2+  if impl(ghc >= 6.8)+    ghc-options: -fwarn-tabs++  exposed-modules:+    Control.Concurrent.ThreadManager++  hs-source-dirs:+    src++  build-depends:+    base        > 3 && < 5,+    containers == 0.5.*++--------------------------------------------------------------------------------+ source-repository head-    type:     git-    location: git://github.com/bsl/threadmanager.git+  type:     git+  location: git://github.com/bsl/threadmanager.git