bounded-qsem- Bounded quantity semaphores.
Safe HaskellSafe



Bounded quantity semaphores.



data BQSem Source #

Bounded quantity semaphore in which the resource is acquired and released in units of one, but with a maximum amount of units available at any given time.

newBQSem Source #


:: Int

Initial unit supply.

-> Int

Maximum unit supply.

-> IO BQSem 

Build a new BQSem with supplied initial and maximum supply. An exception is thrown in any of the following cases:

  • Initial supply is negative.
  • Maximum supply is less than 1.
  • Initial supply exceeds maximum.

waitBQSem :: BQSem -> IO () Source #

Wait for a unit to become available.

signalBQSem :: BQSem -> IO () Source #

Make a new unit available, unless the maximum number of units has been reached, in which case it does nothing (it doesn't block).

getBQSemQuantity :: BQSem -> IO Int Source #

Get current supply quantity.