planet-mitchell-0.0.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Concurrency.TSem

Contents

Synopsis

TSem

data TSem #

TSem is a transactional semaphore. It holds a certain number of units, and units may be acquired or released by waitTSem and signalTSem respectively. When the TSem is empty, waitTSem blocks.

Note that TSem has no concept of fairness, and there is no guarantee that threads blocked in waitTSem will be unblocked in the same order; in fact they will all be unblocked at the same time and will fight over the TSem. Hence TSem is not suitable if you expect there to be a high number of threads contending for the resource. However, like other STM abstractions, TSem is composable.

Since: stm-2.4.2

Instances
Eq TSem 
Instance details

Defined in Control.Concurrent.STM.TSem

Methods

(==) :: TSem -> TSem -> Bool #

(/=) :: TSem -> TSem -> Bool #

newTSem :: Int -> STM TSem #

Construct new TSem with an initial counter value.

A positive initial counter value denotes availability of units waitTSem can acquire.

The initial counter value can be negative which denotes a resource "debt" that requires a respective amount of signalTSem operations to counter-balance.

Since: stm-2.4.2

waitTSem :: TSem -> STM () #

Wait on TSem (aka P operation).

This operation acquires a unit from the semaphore (i.e. decreases the internal counter) and blocks (via retry) if no units are available (i.e. if the counter is not positive).

Since: stm-2.4.2

signalTSem :: TSem -> STM () #

Signal a TSem (aka V operation).

This operation adds/releases a unit back to the semaphore (i.e. increments the internal counter).

Since: stm-2.4.2

signalTSemN :: Word -> TSem -> STM () #

Multi-signal a TSem

This operation adds/releases multiple units back to the semaphore (i.e. increments the internal counter).

signalTSem == signalTSemN 1

Since: stm-2.4.5