Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Semaphore = Semaphore {}
- newtype SemaphoreName = SemaphoreName {}
- createSemaphore :: SemaphoreName -> Int -> IO Semaphore
- freshSemaphore :: String -> Int -> IO Semaphore
- openSemaphore :: SemaphoreName -> IO Semaphore
- waitOnSemaphore :: Semaphore -> IO ()
- tryWaitOnSemaphore :: Semaphore -> IO Bool
- data WaitId = WaitId {}
- forkWaitOnSemaphoreInterruptible :: Semaphore -> (Either SomeException Bool -> IO ()) -> IO WaitId
- interruptWaitOnSemaphore :: WaitId -> IO ()
- getSemaphoreValue :: Semaphore -> IO Int
- releaseSemaphore :: Semaphore -> Int -> IO ()
- destroySemaphore :: Semaphore -> IO ()
- data AbstractSem = AbstractSem {
- acquireSem :: IO ()
- releaseSem :: IO ()
- withAbstractSem :: AbstractSem -> IO b -> IO b
System semaphores
A system semaphore (POSIX or Win32).
newtype SemaphoreName Source #
Instances
Eq SemaphoreName Source # | |
Defined in System.Semaphore (==) :: SemaphoreName -> SemaphoreName -> Bool # (/=) :: SemaphoreName -> SemaphoreName -> Bool # |
:: SemaphoreName | |
-> Int | number of tokens on the semaphore |
-> IO Semaphore |
Create a new semaphore with the given name and initial amount of available resources.
Throws an error if a semaphore by this name already exists.
Create a fresh semaphore with the given amount of tokens.
Its name will start with the given prefix, but will have a random suffix appended to it.
openSemaphore :: SemaphoreName -> IO Semaphore Source #
Open a semaphore with the given name.
If no such semaphore exists, throws an error.
waitOnSemaphore :: Semaphore -> IO () Source #
Indefinitely wait on a semaphore.
If you want to be able to cancel a wait operation, use
forkWaitOnSemaphoreInterruptible
instead.
tryWaitOnSemaphore :: Semaphore -> IO Bool Source #
Try to obtain a token from the semaphore, without blocking.
Immediately returns False
if no resources are available.
WaitId
stores the information we need to cancel a thread
which is waiting on a semaphore.
See forkWaitOnSemaphoreInterruptible
and interruptWaitOnSemaphore
.
forkWaitOnSemaphoreInterruptible Source #
Spawn a thread that waits on the given semaphore.
In this thread, asynchronous exceptions will be masked.
The waiting operation can be interrupted using the
interruptWaitOnSemaphore
function.
interruptWaitOnSemaphore :: WaitId -> IO () Source #
Interrupt a semaphore wait operation initiated by
forkWaitOnSemaphoreInterruptible
.
getSemaphoreValue :: Semaphore -> IO Int Source #
Query the current semaphore value (how many tokens it has available).
This is mainly for debugging use, as it is easy to introduce race conditions when nontrivial program logic depends on the value returned by this function.
releaseSemaphore :: Semaphore -> Int -> IO () Source #
Release a semaphore: add n
to its internal counter.
No-op when `n <= 0`.
destroySemaphore :: Semaphore -> IO () Source #
Destroy the given semaphore.
Abstract semaphores
data AbstractSem Source #
Abstraction over the operations of a semaphore.
AbstractSem | |
|
withAbstractSem :: AbstractSem -> IO b -> IO b Source #