module STM:sig
..end
WARNING: the current implementation has only been lightly tested.
This module provides support for a partial STM, that protects
only values of type STM.ref
.
type 'a
ref
val ref : 'a -> 'a ref
ref
, that can then only be accessed during
a transaction.exception Retry
exception Abort
exception Cancelled
val run : ?retries:int ->
(('a ref -> 'a) -> ('a ref -> 'a -> unit) -> 'b) -> 'b
run ~retries f
executes the function f
inside a newly-created
transaction. Function f
is passed two functions g
and s
that
are to be used as respectively read and write accessors to ref
values. The retries
parameter (defaulting to 64
) indicates how
many time a transaction should be retried. g
and s
will raise
Failure
is they are called from another thread, or outside the
lifetime of the transaction.
The Retry
exception can be raised to requested the current
transaction to be re-executed from the beginning, while any other
exception will cause the transaction to be aborted.
Raises Cancelled
if the transaction cannot be committed, and
retries have been exhausted.
Raises the exception raised by the transaction, if different from
Retry
.
val run_read_only : ?retries:int -> (('a ref -> 'a) -> 'b) -> 'b
run
, but with a smaller overhead due to the fact that the
transaction is guaranteed to only read values.