Copyright | (c) Duncan Coutts 2012 |
---|---|
License | BSD-like |
Maintainer | [email protected] |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Distribution.Client.JobControl
Description
A job control concurrency abstraction
Synopsis
- data JobControl m a
- newSerialJobControl :: IO (JobControl IO a)
- newParallelJobControl :: WithCallStack (Int -> IO (JobControl IO a))
- newSemaphoreJobControl :: WithCallStack (Verbosity -> Int -> IO (JobControl IO a))
- spawnJob :: JobControl m a -> m a -> m ()
- collectJob :: JobControl m a -> m a
- remainingJobs :: JobControl m a -> m Bool
- cancelJobs :: JobControl m a -> m ()
- cleanupJobControl :: JobControl m a -> m ()
- jobControlSemaphore :: JobControl m a -> Maybe SemaphoreName
- data JobLimit
- newJobLimit :: Int -> IO JobLimit
- withJobLimit :: JobLimit -> IO a -> IO a
- data Lock
- newLock :: IO Lock
- criticalSection :: Lock -> IO a -> IO a
Documentation
data JobControl m a Source #
A simple concurrency abstraction. Jobs can be spawned and can complete in any order. This allows both serial and parallel implementations.
newSerialJobControl :: IO (JobControl IO a) Source #
Make a JobControl
that executes all jobs serially and in order.
It only executes jobs on demand when they are collected, not eagerly.
Cancelling will cancel all jobs that have not been collected yet.
newParallelJobControl :: WithCallStack (Int -> IO (JobControl IO a)) Source #
Make a JobControl
that eagerly executes jobs in parallel, with a given
maximum degree of parallelism.
Cancelling will cancel jobs that have not yet begun executing, but jobs that have already been executed or are currently executing cannot be cancelled.
newSemaphoreJobControl :: WithCallStack (Verbosity -> Int -> IO (JobControl IO a)) Source #
Make a JobControl
where the parallism is controlled by a semaphore.
This uses the GHC -jsem option to allow GHC to take additional semaphore slots if we are not using them all.
spawnJob :: JobControl m a -> m a -> m () Source #
Add a new job to the pool of jobs
collectJob :: JobControl m a -> m a Source #
Wait until one job is complete
remainingJobs :: JobControl m a -> m Bool Source #
Returns True if there are any outstanding jobs (ie spawned but yet to be collected)
cancelJobs :: JobControl m a -> m () Source #
Try to cancel any outstanding but not-yet-started jobs.
Call remainingJobs
after this to find out if any jobs are left
(ie could not be cancelled).
cleanupJobControl :: JobControl m a -> m () Source #
cleanup any resources created by the JobControl, intended to be used
as the finaliser for bracket
.
jobControlSemaphore :: JobControl m a -> Maybe SemaphoreName Source #
Name of the semaphore which can be used to control parallelism, if one is available for that job control type.