Module Phaser

module Phaser: sig .. end
Flexible synchronization abstractions, subsuming countdown latches and cyclic barriers.

type t 
The type of phasers, differing from coutdown latches and cyclic barriers by the fact that parties explicitly register.

Phasers are also organized in a tree-like structure, to reduce contention: a phaser is automatically registered/deregistered with its parent when the number of parties becomes respectively non-zero/zero.

The phase number of a phaser starts at zero, and advances when all parties arrive at the phaser.

val make : t option -> int32 -> t
make p n returns a new phaser with parent p, and number of parties n.

Raises Invalid_argument if n is negative.

val arrive : t -> int32
Records that a party has arrived to the phaser without waiting for others, returns the phase number (negative if the phaser is terminated).

Raises Invalid_argument if the phase number would be negative while the phaser is not terminated.

val arrive_and_await_advance : t -> int32
Records that a party has arrived to the phaser and waits for others, returns the phase number (negative if the phaser is terminated).

Raises Invalid_argument if the phase number would be negative while the phaser is not terminated.

val arrive_and_deregister : t -> int32
Records that a party has arrived to the phaser without waiting for others, deregisters a party, returns the phase number (negative if the phaser is terminated).

Raises Invalid_argument if the phase number would be negative while the phaser is not terminated.

val await_advance : t -> int32 -> int32
Waits for the phase number of the phaser to reach the passed value.
val await_advance_interruptibly : t -> int32 -> int32
Similar to await_advance except that the thread can be interrupted.

Raises Runtime.Interrupted if the thread is interrupted.

val await_advance_interruptibly_time : t -> int32 -> int64 -> TimeUnit.t -> int32
await_advance_interruptibly_time p pn t u is similar to await_advance_interruptibly p pn, except that the current thread will at most wait for t (time value whose unit is u).

Raises Runtime.Interrupted if the thread is interrupted.

Raises Runtime.Timeout if time has elapsed without reaching the given phase number.

val bulk_register : t -> int32 -> int32
bulk_register p n adds n unarrived parties to phaser p.

Raises Invalid_argument if n is negative.

Raises Invalid_argument if the maximum number of parties has already been reached.

val force_termination : t -> unit
Forces termination of the phaser, includind children phasers.
val get_arrived_parties : t -> int32
Returns the number of registered parties that have arrived to the phaser.
val get_parent : t -> t option
Returns the parent of the phaser.
val get_phase : t -> int32
Returns the phase number.
val get_registered_parties : t -> int32
Returns the number of registered parties.
val get_root : t -> t
Returns the root that can be reached from the phaser by recursively visiting parents. Returns the passed phaser if it has no parent.
val get_unarrived_parties : t -> int32
Returns the number of registered parties that have not yet arrived to the phaser.
val is_terminated : t -> bool
Tests whether the phaser has been terminated.
val register : t -> int32
Adds a new unarrived party to the phaser, and returns the current phase number

Raises Invalid_argument if the maximum number of parties has already been reached.