package affect

  1. Overview
  2. Docs
Streamlined and natural concurrency model for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

affect-0.0.0.tbz
sha512=b328f6696e60c489da8cc2e8fad0537ca6634a39fc0c5de5840d4f98561f110617ef79ba8285ee8427dd99908c6b3d39114973598cddc5ded91abcce3b91b9a6

doc/affect/Affect/Semaphore/index.html

Module Affect.SemaphoreSource

Semaphores.

A semaphore with capacity n throttles access to a ressource with limited n.

  • An acquire blocks until the semaphore's value can be decremented to a non-negative integer.
  • A release increments the value of the semaphore. It doesn't block but it is a programming error to increment it over n.

Semaphores

Sourcetype t

The type for semaphores.

Sourceval make : int -> t

make n is a semaphore with a capacity of n.

Sourceval acquire : t -> unit

acquire s blocks until s can be decremented to a non-negative integer.

Sourceval release : t -> unit

release s increments the value of s. If there are multiple blocked acquire on s, only the earliest acquire unblocks.

  • raises Invalid_argument

    if value of s exceeds the capacity after the increment. XXX. The stdlib uses Sys_error, check why.

Sourceval with_acquired : t -> (unit -> 'a) -> 'a

with_acquired s f acquires s executes f () and releases s when f returns a value or an exception.

Properties

Sourceval get_value : t -> int

get_value s is the current value of semaphore s.

Sourceval capacity : t -> int

capacity s is the capacity of s.

Actions

Sourceval acquire' : t -> 'tag -> 'tag Action.t

acquire' s tag is the action for acquire. An action invocation is enabled when s is non-zero. The invocation synchronizes with tag if it manages to decrement s to a non-negative value.