Control-Monad-MultiPass-0.1.0.0: A Library for Writing Multi-Pass Algorithms.

Safe HaskellSafe

Control.Monad.MultiPass.Instrument.Counter

Description

The Counter instrument is used to generate an increasing sequence of integers. It is particularly useful when the program uses parallelism, because the Counter instrument creates the illusion of a single-threaded global counter. The first pass counts how many unique integers each thread needs so that the integers can be generated without the use of locks during the second pass.

Synopsis

Documentation

data Counter i r w p1 p2 tc Source

Abstract datatype for the instrument.

Instances

Instrument tc () () (Counter i r w Off Off tc) 
Num i => Instrument tc (CounterTC2 i r) () (Counter i r w On On tc) 
Num i => Instrument tc (CounterTC1 i r) () (Counter i r w On Off tc) 

peek :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)Source

Get the current value of the counter.

addkSource

Arguments

:: (Num i, Monad p1, Monad p2) 
=> Counter i r w p1 p2 tc

counter

-> p1 i

k

-> MultiPass r w tc () 

Add k to the counter.

incr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc ()Source

Increment the counter.

preIncr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)Source

Read and pre-increment the counter. For example, if the current value is 17 then preIncr updates the value of the counter to 18 and returns 18.

postIncr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)Source

Read and post-increment the counter. For example, if the current value is 17 then postIncr updates the value of the counter to 18 and returns 17.