Module Semaphore

module Semaphore: sig .. end
Semaphores.

type t 
The type of semaphores, each maintaining a set of available permits.
val make : int32 -> bool -> t
make p f returns a new semaphore with p permits, f indicating whether a fair ordering policy is requested.

p can be negative, meaning that permits should be released before any acquisition.

val acquire : t -> int32 -> unit
acquire s p acquires p permits from semaphore s, blocking until they are available.

Raises Invalid_argument if p is negative.

Raises Runtime.Interrupted if the thread is interrupted.

val acquire_uninterruptibly : t -> int32 -> unit
acquire_uninterruptibly s p is similar to acquire s p, except that waiting thread cannot be interrupted.

Raises Invalid_argument if p is negative.

val available_permits : t -> int32
Returns the number of available permits for the semaphore.
val drain_permits : t -> int32
Acquires and returns all available permits from the semaphore, returning immediately.
val get_queue_length : t -> int32
Returns an estimate of the number of threads waiting on the semaphore to acquire permits.
val has_queued_threads : t -> bool
Tests whether there are threads waiting on the semaphore to acquire permits.
val is_fair : t -> bool
Tests whether the semaphore uses a fair policy.
val release : t -> int32 -> unit
release s p releases p permits from semaphore s.

Raises Invalid_argument if p is negative.

val try_acquire : t -> int32 -> bool
try_acquire s p is similar to acquire s p, except the function always returns immediately returning true if acquisition was successful.

Raises Invalid_argument if p is negative.

val try_acquire_time : t -> int32 -> int64 -> TimeUnit.t -> bool
try_acquire_time s p t u is similar to try_acquire s p, except that the current thread will at most wait for t (time value whose unit is u).

Raises Invalid_argument if p is negative.

Raises Runtime.Interrupted if the thread is interrupted.