module Phaser: sig .. end
Flexible synchronization abstractions, subsuming countdown latches
and cyclic barriers.
type t = java'util'concurrent'Phaser java_instance
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 : ?parent:t -> ?parties:int32 -> unit -> t
make ~parent:p ~parties:n
returns a new phaser with parent
p
(defaulting to
null
), and number of parties
n
(defaulting to
0l
); see
Phaser(...).
Raises Java_exception
if
n
is negative
val arrive : t -> java_int
Records that a party has arrived to the phaser without waiting for
others, returns the phase number (negative if the phaser is
terminated); see
arrive(...).
Raises Java_exception
if the phase number would be negative while
the phaser is not terminated
val arrive_and_await_advance : t -> java_int
Records that a party has arrived to the phaser and waits for others,
returns the phase number (negative if the phaser is terminated); see
arriveAndAwaitAdvance(...).
Raises Java_exception
if the phase number would be negative while
the phaser is not terminated
val arrive_and_deregister : t -> java_int
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); see
arriveAndDeregister(...).
Raises Java_exception
if the phase number would be negative while
the phaser is not terminated
val await_advance : t -> java_int -> java_int
Waits for the phase number of the phaser to reach the passed value; see
awaitAdvance(...).
val await_advance_interruptibly : t -> java_int -> java_int
val await_advance_interruptibly_time : t -> java_int -> java_long -> TimeUnit.t -> java_int
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
); see
awaitAdvanceInterruptibly(...).
RaisesJava_exception
if the thread is interrupted
Java_exception
if time has elapsed without reaching the
given phase number
val bulk_register : t -> java_int -> java_int
bulk_register p n
adds
n
unarrived parties to phaser
p
; see
bulkRegister(...).
RaisesJava_exception
if n
is negative
Java_exception
if the maximum number of parties has
already been reached
val force_termination : t -> unit
val get_arrived_parties : t -> java_int
val get_phase : t -> java_int
val get_registered_parties : t -> java_int
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; see
getRoot(...).
val get_unarrived_parties : t -> java_int
val is_terminated : t -> bool
val register : t -> java_int
Adds a new unarrived party to the phaser, and returns the current
phase number; see
register(...).
Raises Java_exception
if the maximum number of parties has already
been reached
Null value
val null : t
The null
value.
val is_null : t -> bool
is_null obj
returns true
iff obj
is equal to null
.
val is_not_null : t -> bool
is_not_null obj
returns false
iff obj
is equal to null
.
Miscellaneous
val wrap : t -> t option
wrap obj
wraps the reference
obj
into an option type:
Some x
if obj
is not null
;
None
if obj
is null
.
val unwrap : t option -> t
unwrap obj
unwraps the option
obj
into a bare reference:
Some x
is mapped to x
;
None
is mapped to null
.