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

Portabilitynon-portable (requires Futures)



This module implements a quantity semaphore using handles that block on futures. A HQSem equals to QSemN in Control.Concurrent. A Buffer euqals to QSem in Control.Concurrent. Warning: All operations on quantity semaphores should only be used within the global wrapper function withFuturesDo!



type HQSem = Buffer (Int, [Bool -> IO ()])Source

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

newHQSem :: Int -> IO HQSemSource

Creates a new quantity semaphore of capacity cnt.

upHQSem :: HQSem -> IO ()Source

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

downHQSem :: HQSem -> IO BoolSource

Decrements the semaphore's value. If the value has already reached 0, then down creates a new handle that is being added to the semaphore's waiting queue. It blocks until the handle assigns a value to its future by a up. Note: This operation equals to waitQSemN in Control.Concurrent.QSemN.