Module CCSemaphore
Semaphores
- since
- 0.13
val create : int -> t
create n
creates a semaphore with initial valuen
.- raises Invalid_argument
if
n <= 0
.
val get : t -> int
Current value.
val acquire : int -> t -> unit
acquire n s
blocks untilget s >= n
, then atomically setss := !s - n
.
val release : int -> t -> unit
release n s
atomically setss := !s + n
.
val with_acquire : n:int -> t -> f:(unit -> 'a) -> 'a
with_acquire ~n s ~f
first acquiress
withn
units, callsf ()
, and then releasess
withn
units. Safely release the semaphore even iff ()
fails.
val wait_until_at_least : n:int -> t -> f:(unit -> 'a) -> 'a
wait_until_at_least ~n s ~f
waits untilget s >= n
, then callsf ()
and returns its result. Doesn't modify the semaphore.