Module Semaphore

module Semaphore: sig .. end
Semaphore operations

type t 
exception Error of int * string
The number carried with the exception can come from:

POSIX: errno (it corresponds to Unix.error)

Windows: GetLastError()

val unnamed_create : int -> t
unnamed_create initial_count returns a fresh semaphore with given initial count. To be destroyed with Semaphore.unnamed_destroy.
val unnamed_destroy : t -> unit
Frees all resources related to the semaphore.
val named_open : int -> string -> t
named_open initial_count name creates new or opens existing named semaphore that can be shared across processes. name is modified to comply with OS requirements, the following strings are prepended:

POSIX: "/"

Windows: "Global\"

If the semaphore already exists, the argument initial_count is ignored and state of the semaphore is left unchanged. Otherwise, the number initializes the newly created semaphore.


val named_close : t -> unit
Closes the descriptor/handle of the semaphore.

Windows: OS can remove the semaphore after this function is called, if it is no longer used.

POSIX: Additional call to Semaphore.named_unlink is required to remove the semaphore from the system.

val named_unlink : string -> unit
If the semaphore is not in use, a call to this function guarantees that the semaphore no longer exists.

type achievement =
| Decremented
| Failed
Result of Semaphore.try_wait operation.
val wait : t -> unit
P, proberen, decrease, decrement, down, wait, acquire, pend, procure.
val try_wait : t -> achievement
Tries to decrement the semaphore, but doesn't enter waiting state if fails.
val signal : t -> unit
V, verhogen, increase, increment, up, signal, release, post, vacate.
val do_with_unnamed : int -> (t -> 'a) -> 'a
Creates an unnamed semaphore with given initial count, applies it to the given function, destroys the semaphore (regardless any raised exception), returns the result of the application.