Library
Module
Module type
Parameter
Class
Class type
Explicit transaction log passing on shared memory locations.
Type of an explicit transaction log on shared memory locations.
Note that a transaction log itself is not domain-safe and should generally only be used by a single domain. If a new domain is spawned inside a function recording shared memory accesses to a log and the new domain also records accesses to the log it may become inconsistent.
Accesses of shared memory locations using an explicit transaction log first ensure that the initial value of the shared memory location is recorded in the log and then act on the current value of the shared memory location as recorded in the log.
get ~xt r
returns the current value of the shared memory location r
in the explicit transaction log xt
.
set ~xt r v
records the current value of the shared memory location r
to be the given value v
in the explicit transaction log xt
.
update ~xt r f
is equivalent to let x = get ~xt r in set ~xt r (f x); x
with the limitation that f
must not and is not allowed to access the transaction log.
modify ~xt r f
is equivalent to let x = get ~xt r in set ~xt r (f x)
with the limitation that f
must not and is not allowed to access the transaction log.
exchange ~xt r v
is equivalent to update ~xt r (fun _ -> v)
.
swap ~xt l1 l2
is equivalent to set ~xt l1 @@ exchange ~xt l2 @@ get ~xt l1
.
compare_and_swap ~xt r before after
is equivalent to
update ~xt r @@ fun actual ->
if actual == before then after else actual
fetch_and_add ~xt r n
is equivalent to update ~xt r ((+) n)
.
decr ~xt r
is equivalent to fetch_and_add ~xt r (-1) |> ignore
.
val post_commit : xt:'x t -> (unit -> unit) -> unit
post_commit ~xt action
adds the action
to be performed after the transaction has been performed successfully.
is_in_log ~xt r
determines whether the shared memory location r
has been accessed by the transaction.
Type of a transaction function that is polymorphic with respect to an explicit transaction log. The universal quantification helps to ensure that the transaction log cannot accidentally escape.
attempt tx
attempts to atomically perform the transaction over shared memory locations recorded by calling tx
with a fresh explicit transaction log. If used in Mode.obstruction_free
may raise Mode.Interference
. Otherwise either raises Exit
on failure to commit the transaction or returns the result of the transaction. The default for attempt
is Mode.lock_free
.
commit tx
repeats attempt tx
until it does not raise Exit
or Mode.Interference
and then either returns or raises whatever attempt returned or raised.
The default for commit
is Mode.obstruction_free
. However, after enough attempts have failed during the verification step, commit
switches to Mode.lock_free
.
Note that, aside from using exponential backoff to reduce contention, the transaction mechanism has no way to intelligently wait until shared memory locations are modified by other domains.
of_tx tx
converts the given Tx
transaction tx
to an explicit log passing function.