package index

  1. Overview
  2. Docs

Binary semaphores for mutual exclusion

type t

The type of binary semaphore.

val make : bool -> t

make b returns a new semaphore with the given initial state. If b is true, the semaphore is initially available for acquisition; otherwise, the semaphore is initially unavailable.

val acquire : string -> t -> unit

Acquire the given semaphore. Acquisition is not re-entrant.

val release : t -> unit

Release the given semaphore. If any threads are attempting to acquire the semaphore, exactly one of them will gain access to the semaphore.

val with_acquire : string -> t -> (unit -> 'a) -> 'a

with_acquire t f first obtains t, then computes f (), and finally release t.

val is_held : t -> bool

is_held t returns true if the semaphore is held, without acquiring t.