HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Modulesemaphore-compat-2.0.1Haskell2010

System.Semaphore.Internal.Posix.Server

The Unix domain socket server backing the POSIX semaphore implementation.

The server manages a shared token pool and accepts multiple client connections, each served on its own thread.

Protocol (SOCK_STREAM, one byte per command):

"-" Wait (blocking acquire). Decrements semaphore; replies ".". "?" Try-wait. Decrements if positive and replies "."; otherwise replies "!". "+" Release. Increments pool; replies ".". Rejected with "!" if myCount <= 0 (client has not acquired any tokens on this connection).

Unrecognised bytes are rejected with RspFail.

Per-connection token tracking: the server counts tokens held by each connection (myCount). On disconnect (EOF / ResourceVanished) held tokens are returned to the pool, so a crashing client cannot leak tokens.

Connections are tied to a token, so each token (obtained by waitOnSemaphore) has its own connection.

  • 1 value
valueserverLoop
  1. :: TVar Int

    shared token pool

  2. -> Fd

    listening socket

  3. -> Fd

    read end of the cancel pipe

  4. -> IO ()
#

Run the server accept loop on a listening socket until cancellation is signalled via the cancel pipe. All accepted connections are served on child threads, which are cleaned up before this returns.