semaphore-compat: Cross-platform abstraction for system semaphores

[ bsd3, library, system ] [ Propose Tags ] [ Report a vulnerability ]

Cross-platform semaphores for managing resources across processes, abstracting over Win32 named semaphores on Windows and Unix domain sockets on POSIX.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
build-testing

Build test helper library, executable, and test suite

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0, 2.0.0
Change log changelog.md
Dependencies base (>=4.11 && <4.23), containers (>=0.5 && <0.9), directory (>=1.3 && <1.4), exceptions (>=0.7 && <0.11), filepath (>=1.4 && <1.6), process (>=1.6.16 && <1.8), semaphore-compat, stm (>=2.4 && <2.6), unix (>=2.8.1.0 && <2.9), Win32 (>=2.13.4.0 && <2.15) [details]
License BSD-3-Clause
Author The GHC team
Maintainer ghc-devs@haskell.org
Uploaded by wz1000 at 2026-05-25T10:36:08Z
Category System
Home page https://gitlab.haskell.org/ghc/semaphore-compat
Bug tracker https://gitlab.haskell.org/ghc/ghc/issues/new
Source repo head: git clone https://gitlab.haskell.org/ghc/semaphore-compat.git
Distributions Fedora:1.0.0
Reverse Dependencies 4 direct, 15985 indirect [details]
Executables semaphore-helper
Downloads 1540 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-05-25 [all 1 reports]

Readme for semaphore-compat-2.0.0

[back to package description]

semaphore-compat

semaphore-compat provides cross-platform semaphores that can be shared across processes.

It uses different backends on different platforms:

  • POSIX: Unix domain sockets with automatic return of tokens from disconnected clients.
  • Windows: Win32 named semaphores. Tokens held by crashed clients are not returned automatically.
  • wasm/JavaScript: buildable stubs that throw unsupported-operation errors. Avoid calling this code on these backends.

It supports:

  • Creating server semaphores (createSemaphore, freshSemaphore).
    • A server is the process that creates the semaphore and must stay alive for the duration of its use.
    • A server process can also act as a client and request/release tokens from the semaphore.
  • Opening client semaphores (openSemaphore).
  • Waiting with tryWaitOnSemaphore or interruptible waitOnSemaphore, which return SemaphoreTokens.
  • Releasing tokens with releaseSemaphoreToken or withSemaphoreToken.
  • Destroying semaphores with destroyClientSemaphore and destroyServerSemaphore.
  • Serialising names and checking versions with semaphoreIdentifier and versionsAreCompatible.