Control.Concurrent.STM.TSem

stm-2.4.4.1: Software Transactional Memory

Copyright | (c) The University of Glasgow 2012
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | non-portable (requires STM)
Safe Haskell | Safe
Language | Haskell2010

Control.Concurrent.STM.TSem

Description

`TSem`: transactional semaphores.

Since: 2.4.2

Synopsis

- data TSem
- newTSem :: Int -> STM TSem
- waitTSem :: TSem -> STM ()
- signalTSem :: TSem -> STM ()

# Documentation

data TSem Source #

`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: 2.4.2

Instances

Eq TSem # |
Instance details Methods (==) :: TSem -> TSem -> Bool # (/=) :: TSem -> TSem -> Bool #

newTSem :: Int -> STM TSem Source #

waitTSem :: TSem -> STM () Source #

signalTSem :: TSem -> STM () Source #