caf-0.0.3: A library of Concurrency Abstractions using Futures.

Portabilitynon-portable (requires Futures)
Stabilityexperimental
Maintainerwillig@ki.informatik.uni-frankfurt.de

Control.Concurrent.Futures.QSem

Description

This module implements a quantity semaphore using buffers that block on futures.

A QSem equals to QSemN in Control.Concurrent. A Buffer equals to QSem in Control.Concurrent.

Warning: All operations on quantity semaphores should only be used within the global wrapper function Futures.withFuturesDo!

Synopsis

Documentation

type QSem = Buffer (Int, [Buffer Bool])Source

A quantity semaphores contains of a capacity and a waiting queue containing buffers.

newQSem :: Int -> IO (Buffer (Int, [Buffer Bool]))Source

Creates a new quantity semaphore of capacity cnt.

up :: QSem -> IO ()Source

Increments the semaphore's value, if there are no waiters. up reads out of the waiting queue and writes True into a waiting Buffer. Note: This operation equals to signalQSemN in Control.Concurrent.QSemN.

down :: QSem -> IO BoolSource

Decrements the semaphore's value. If the value has already reached zero, then down creates a new empty Buffer that is being added to the semaphore's waiting queue. It blocks until the buffer gets filled by a up. Note: This operation equals to waitQSemN in Control.Concurrent.QSemN.

enter :: QSem -> IO a -> IO ()Source

Use the quantity semaphore to limit the computation of code. This function performs a down on the given q. s., executues the code and returns after a up on the q.s. .