Safe Haskell | Safe |
---|
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.
- data Counter i r w p1 p2 tc
- peek :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)
- addk :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> p1 i -> MultiPass r w tc ()
- incr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc ()
- preIncr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)
- postIncr :: (Num i, Monad p1, Monad p2) => Counter i r w p1 p2 tc -> MultiPass r w tc (p2 i)
Documentation
data Counter i r w p1 p2 tc Source
Abstract datatype for the instrument.
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.
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.