| Safe Haskell | Safe |
|---|
Control.Monad.MultiPass.ThreadContext.CounterTC
Contents
Description
CounterTC defines a
thread context which is used to generate a series of unique
consecutive numbers. It has two passes. The first pass,
CounterTC1, creates a log of the number of new values that need
to be generated in each thread. The second pass, CounterTC2, uses
the log to compute the correct starting value for each thread, so
that the threads appear to be incrementing a single global counter,
even though they are operating concurrently.
- data CounterTC1 i r
- counterVal1 :: CounterTC1 i r -> i
- incrCounterTC1 :: Num i => CounterTC1 i r -> CounterTC1 i r
- addkCounterTC1 :: Num i => i -> CounterTC1 i r -> CounterTC1 i r
- newCounterTC1 :: Num i => CounterTC1 i r
- data CounterTC2 i r
- counterVal2 :: CounterTC2 i r -> i
- incrCounterTC2 :: Num i => CounterTC2 i r -> CounterTC2 i r
- addkCounterTC2 :: Num i => i -> CounterTC2 i r -> CounterTC2 i r
- newCounterTC2 :: Num i => CounterTC1 i r -> ST2 r w (CounterTC2 i r)
- resetCounterTC2 :: Num i => CounterTC2 i r -> CounterTC2 i r
First Pass
data CounterTC1 i r Source
CounterTC1 is used during the first pass. It builds up a log of
the parallel tasks that were spawned, which is used during the
second pass to generate a series of unique consecutive numbers.
Instances
| Num i => NextThreadContext r w () gc (CounterTC1 i r) | |
| Num i => ThreadContext r w (CounterTC1 i r) | |
| Num i => NextThreadContext r w (CounterTC2 i r) gc (CounterTC1 i r) | |
| Num i => NextThreadContext r w (CounterTC1 i r) gc (CounterTC2 i r) | |
| Num i => NextThreadContext r w (CounterTC1 i r) gc (CounterTC1 i r) | |
| Num i => Instrument tc (CounterTC1 i r) () (Counter i r w On Off tc) | |
| Instrument tc (CounterTC1 Int r) () (Knot3 a r w On Off Off tc) | |
| Num i => Instrument tc (CounterTC1 i r) () (EmitST2Array i a r w On Off Off tc) |
counterVal1 :: CounterTC1 i r -> iSource
Get the current value of the counter.
incrCounterTC1 :: Num i => CounterTC1 i r -> CounterTC1 i rSource
Increment the counter.
addkCounterTC1 :: Num i => i -> CounterTC1 i r -> CounterTC1 i rSource
Add k to the counter.
newCounterTC1 :: Num i => CounterTC1 i rSource
Create a new counter.
Second Pass
data CounterTC2 i r Source
CounterTC2 is used during the second pass. It uses the log
which was computed by CounterTC1 to generate a series of unique
consecutive numbers.
Instances
| Num i => ThreadContext r w (CounterTC2 i r) | |
| Num i => NextThreadContext r w (CounterTC2 i r) gc (CounterTC2 i r) | |
| Num i => NextThreadContext r w (CounterTC2 i r) gc (CounterTC1 i r) | |
| Num i => NextThreadContext r w (CounterTC1 i r) gc (CounterTC2 i r) | |
| Num i => Instrument tc (CounterTC2 i r) () (Counter i r w On On tc) |
counterVal2 :: CounterTC2 i r -> iSource
Get the current value of the counter.
incrCounterTC2 :: Num i => CounterTC2 i r -> CounterTC2 i rSource
Increment the counter.
addkCounterTC2 :: Num i => i -> CounterTC2 i r -> CounterTC2 i rSource
Add k to the counter.
newCounterTC2 :: Num i => CounterTC1 i r -> ST2 r w (CounterTC2 i r)Source
Convert a CounterTC1 to a CounterTC2.
resetCounterTC2 :: Num i => CounterTC2 i r -> CounterTC2 i rSource
Reset the counter to zero and rewind to the beginning of the log.