Win32-2.14.1.0: A binding to Windows Win32 API.
Copyright(c) Sam Derbyshire 2022
LicenseBSD-style (see the file libraries/base/LICENSE)
MaintainerSam Derbyshire
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

System.Win32.Semaphore

Description

Windows Semaphore objects and operations

Synopsis

Semaphores

newtype Semaphore Source #

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.

Constructors

Semaphore 

Access modes

Managing semaphores

createSemaphore Source #

Arguments

:: Maybe SECURITY_ATTRIBUTES 
-> LONG

initial count i with 0 <= i <= m

-> LONG

maximum count m > 0

-> 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.

openSemaphore Source #

Arguments

:: 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.

releaseSemaphore :: Semaphore -> LONG -> IO LONG Source #

Increase the count of the Semaphore by the specified amount.

Returns the count of the semaphore before the increase.

Throws an error if the count would exceeded the maximum count of the semaphore.