Copyright | (c) Sam Derbyshire 2022 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | Sam Derbyshire |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Windows Semaphore objects and operations
Synopsis
- newtype Semaphore = Semaphore {}
- type AccessMode = UINT
- sEMAPHORE_ALL_ACCESS :: AccessMode
- sEMAPHORE_MODIFY_STATE :: AccessMode
- createSemaphore :: Maybe SECURITY_ATTRIBUTES -> LONG -> LONG -> Maybe String -> IO (Semaphore, Bool)
- openSemaphore :: AccessMode -> Bool -> String -> IO Semaphore
- releaseSemaphore :: Semaphore -> LONG -> IO LONG
Semaphores
A Windows semaphore.
To obtain a Semaphore
, use createSemaphore
to create a new one,
or openSemaphore
to open an existing one.
To wait on a semaphore, use waitForSingleObject
.
To release resources on a semaphore, use releaseSemaphore
.
To free a semaphore, use closeHandle
.
The semaphore object is destroyed when its last handle has been closed.
Closing the handle does not affect the semaphore count; therefore, be sure to call
releaseSemaphore
before closing the handle or before the process terminates.
Otherwise, pending wait operations will either time out or continue indefinitely,
depending on whether a time-out value has been specified.
Access modes
type AccessMode = UINT Source #
Managing semaphores
:: Maybe SECURITY_ATTRIBUTES | |
-> LONG | initial count |
-> LONG | maximum count |
-> Maybe String | (optional) semaphore name (case-sensitive, limited to MAX_PATH characters) |
-> IO (Semaphore, Bool) |
Open a Semaphore
with the given name, or create a new semaphore
if no such semaphore exists, with initial count i
and maximum count m
.
The counts must satisfy i >= 0
, m > 0
and i <= m
.
The returned Bool
is True
if the function found an existing semaphore
with the given name, in which case a handle to that semaphore is returned
and the counts are ignored.
Use openSemaphore
if you don't want to create a new semaphore.
:: AccessMode | desired access mode |
-> Bool | should child processes inherit the handle? |
-> String | name of the semaphore to open (case-sensitive) |
-> IO Semaphore |
Open an existing Semaphore
.