Copyright | (c) 2018 Michael Walker |
---|---|

License | MIT |

Maintainer | Michael Walker <mike@barrucadu.co.uk> |

Stability | stable |

Portability | portable |

Safe Haskell | None |

Language | Haskell2010 |

`TSem`

: transactional semaphores.

**Deviations:** There is no `Eq`

instance for `TSem`

type.

# Documentation

`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: 1.6.1.0*

newTSem :: MonadSTM stm => Integer -> stm (TSem stm) Source #

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: 1.6.1.0*