| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
A system semaphore (POSIX or Win32).
| Semaphore | |
Fields
| |
newtype SemaphoreName Source
| SemaphoreName | |
Fields | |
| Eq SemaphoreName Source | |
Defined in System.Semaphore Methods(==) :: 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.
| WaitId | |
Fields | |
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.
This implements a similar pattern to the forkFinally 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.
data AbstractSem Source
Abstraction over the operations of a semaphore.
| AbstractSem | |
Fields
| |
withAbstractSem :: AbstractSem -> IO b -> IO b Source
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/9.12.1/docs/libraries/semaphore-compat-1.0.0-3c38/System-Semaphore.html