gang-of-threads-3.2.1: Non-deterministic parallelism with bags

PortabilityPOSIX
Stabilityexperimental
Maintainerbastianholst@gmx.de
Safe HaskellNone

Control.Concurrent.Bag.Implicit

Description

High level bag of tasks interface based on Control.Concurrent.Bag.Basic. Tasks can only return results and add new tasks as intended and it is not possible to add new tasks from the outside or from the action processing the results.

Synopsis

Documentation

newTaskBagSource

Arguments

:: BufferType

buffer type

-> 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.

-> [TaskIO r (Maybe r)]

list of initial tasks

-> IO [r]

lazy result list

Build and start a new task bag.

The returned list is not evaluated yet, but will be evaluated on demand later. Already computed results will be kept in a buffer until the result list is evaluated. If the result list gets garbage collected, the bag of tasks will be stopped automatically.

newEvalBagSource

Arguments

:: BufferType

buffer type

-> 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.

-> [r]

given expressions to evaluate

-> IO [r]

lazy result list

Like newTaskBag, but it takes a list of expressions that will be evaluated to weak head normal form using seq.

__WARNING__: This does not evaluate to normal form, but only to weak head normal form.

type SplitFunction r = TaskBufferSTM (IO (Maybe r)) -> TaskBufferSTM (IO (Maybe r)) -> STM (IO (Maybe r))Source

Split functions are used to split the contents of the source buffer into two parts. One part is left in this buffer or put back later; the other part is written into the sink buffer. One element of this part is returned in the STM monad. This is why the source buffer should always have at least one item available. If it has not, the action will suspend.

takeFirst :: SplitFunction rSource

Just take the first item from the source buffer.

newInterruptingBagSource

Arguments

:: BufferType

buffer type

-> 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.

-> [Interruptible r]

list of initial tasks

-> IO [r]

lazy result list

Similar to newInterruptibleBag, but interrupts the tasks in certain intervals. Using a TChan as buffer, this ensures completeness: all tasks that have a result will get their time to evaluate it. Note, that calculations, that do no memory allocation, cannot be interrupted.

newInterruptibleBagSource

Arguments

:: BufferType

buffer type

-> 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.

-> [Interruptible r]

list of initial tasks

-> IO [r]

lazy result list

Similar to newTaskBag, but taking a list of Interruptible instead of tasks.

data BufferType Source

The type of a buffer. At this time you can only select between Queue and Stack.

Constructors

Queue

A first in first out (FIFO) buffer.

Stack

A last in first out (LIFO) buffer.