Module CCSemaphore
Semaphores
- since
- 0.13
val create : int -> tcreate ncreates a semaphore with initial valuen.- raises Invalid_argument
if
n <= 0.
val get : t -> intCurrent value.
val acquire : int -> t -> unitacquire n sblocks untilget s >= n, then atomically setss := !s - n.
val release : int -> t -> unitrelease n satomically setss := !s + n.
val with_acquire : n:int -> t -> f:(unit -> 'a) -> 'awith_acquire ~n s ~ffirst acquiresswithnunits, callsf (), and then releasesswithnunits. Safely release the semaphore even iff ()fails.
val wait_until_at_least : n:int -> t -> f:(unit -> 'a) -> 'await_until_at_least ~n s ~fwaits untilget s >= n, then callsf ()and returns its result. Doesn't modify the semaphore.