package xapi-stdext-threads

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type t
exception Inconsistent_state of string
val create : int -> t

create n create a semaphore with initial value n (a positive integer). Raise Invalid_argument if n <= 0

val acquire : t -> int -> unit

acquire k s block until the semaphore value is >= k (a positive integer), then atomically decrement the semaphore value by k. Raise Invalid_argument if k <= 0

val release : t -> int -> unit

release k s atomically increment the semaphore value by k (a positive integer). Raise Invalid_argument if k <= 0

val execute_with_weight : t -> int -> (unit -> 'a) -> 'a

execute_with_weight s k f acquire the semaphore with k, then run f (), and finally release the semaphore with the same value k (even in case of failure in the execution of f). Return the value of f () or re-raise the exception if any.

val execute : t -> (unit -> 'a) -> 'a

execute s f same as {execute_with_weight} s 1 f

OCaml

Innovation. Community. Security.