Eio.Semaphore
A counting semaphore.
The API is based on OCaml's Semaphore.Counting
.
The difference is that when waiting for the semaphore this will switch to the next runnable fiber, whereas the stdlib one will block the whole domain.
Semaphores are thread-safe and so can be shared between domains and used to synchronise between them.
val make : int -> t
make n
returns a new counting semaphore, with initial value n
. The initial value n
must be nonnegative.
val release : t -> unit
release t
increments the value of semaphore t
. If other fibers are waiting on t
, the one that has been waiting the longest is resumed.
val acquire : t -> unit
acquire t
blocks the calling fiber until the value of semaphore t
is not zero, then atomically decrements the value of t
and returns.
val get_value : t -> int
get_value t
returns the current value of semaphore t
.