Portability | POSIX |
---|---|
Stability | experimental |
Maintainer | bastianholst@gmx.de |
Safe Haskell | Safe-Inferred |
This is a low-level interface to the bag of tasks, which should only be used if it is not possible to use Control.Concurrent.Bag.Safe for your task. This module allows more control but it also requires a deeper knowledge about the implementation.
- data Bag r
- newBag :: MonadIO m => BufferType -> Maybe (SplitFunction r) -> Int -> m (Bag r)
- newBag_ :: MonadIO m => BufferType -> Maybe (SplitFunction r) -> m (Bag r)
- addEval :: MonadIO m => Bag r -> r -> m ()
- addTask :: MonadIO m => Bag r -> IO (Maybe r) -> m ()
- getResult :: MonadIO m => Bag r -> m (Maybe r)
- writeResult :: MonadIO m => Bag r -> r -> m ()
- terminateBag :: MonadIO m => Bag r -> m ()
- noMoreTasks :: MonadIO m => Bag r -> m ()
- module Control.Concurrent.Bag.TaskBufferSTM
Documentation
:: MonadIO m | |
=> BufferType | type of the used buffer(s) |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. |
-> Int | number of threads |
-> m (Bag r) |
Build and return a new bag of tasks
:: MonadIO m | |
=> BufferType | type of the used buffer(s) |
-> Maybe (SplitFunction r) | Possible split function If the function is given, we will create a bag with one buffer per worker reducing the communication between the workers. buffer per thread |
-> m (Bag r) |
Build and return a new bag of tasks with a default number of worker threads.
addEval :: MonadIO m => Bag r -> r -> m ()Source
Add the evaluation of a haskell expression.
The given expression will be evaluated to weak head normal form.
writeResult :: MonadIO m => Bag r -> r -> m ()Source
Write back a result to be read by getResult
.
terminateBag :: MonadIO m => Bag r -> m ()Source
Terminates all threads running in the thread pool. terminateBag
is
non-blocking and therefore does not guarantee that all threads are
terminated after its executions. Additionally it is not guaranteed
that the treads are terminated promptly. It is implemented using
asynchronous exceptions and therefore it terminates a thread once it uses
a safe point. A safe point is where memory allocation occurs. Although
most tasks will have some point of memory allocation now and the, there
are loops that will never reach a safe point.
noMoreTasks :: MonadIO m => Bag r -> m ()Source
Tell the bag that there will be no more tasks from the outside, however, queued tasks may still add new tasks.