Performs a transactional read and checks that it is consistent with all
reads already made by txn
.
Performs a transactional read and checks that it is consistent with all
reads already made by txn
. Equivalent to apply()
, which is more
concise in many situations.
an active transaction.
the value of the Ref
as observed by txn
.
if txn
is not active.
Returns f(get)
, possibly reevaluating f
to avoid rollback if a
conflicting change is made but the old and new values are equal after
application of f
.
Returns f(get)
, possibly reevaluating f
to avoid rollback if a
conflicting change is made but the old and new values are equal after
application of f
. Requires that f(x) == f(y)
if x == y
.
getWith(f)
is equivalent to f(relaxedGet({ f(_) == f(_) }))
, although
perhaps more efficient.
an idempotent function.
the result of applying f
to the value contained in this Ref
.
Returns the same value as get
, but allows the caller to determine
whether txn
should be rolled back if another thread changes the value
of this Ref
before txn
is committed.
Returns the same value as get
, but allows the caller to determine
whether txn
should be rolled back if another thread changes the value
of this Ref
before txn
is committed. If ref.relaxedGet(equiv)
returns v0
in txn
, another context changes ref
to v1
, and
equiv(v0, v1) == true
, then txn
won't be required to roll back (at
least not due to this read). If additional changes are made to ref
additional calls to the equivalence function will be made, always with
v0
as the first parameter.
equiv
will always be invoked on the current thread. Extreme care
should be taken if the equivalence function accesses any Ref
s.
As an example, to perform a read that will not be validated during commit you can use the maximally permissive equivalence function:
val unvalidatedValue = ref.relaxedGet({ (_, _) => true })
To check view serializability rather than conflict serializability for a read:
val viewSerializableValue = ref.relaxedGet({ _ == _ })
The getWith
method provides related functionality.
an equivalence function that returns true if a transaction that observed the first argument will still complete correctly, where the second argument is the actual value that should have been observed.
a value of the Ref
, not necessary consistent with the rest of
the reads performed by txn
.
See Ref.single
.
Performs a transactional read and checks that it is consistent with all
reads already made by txn
.
Performs a transactional read and checks that it is consistent with all
reads already made by txn
. Equivalent to get
.
Example:
val x = Ref(0) atomic { implicit t => ... val v = x() // perform a read inside a transaction ... }
an active transaction.
the value of the Ref
as observed by txn
.
if txn
is not active.
Returns a string representation of the transactional value in this instance for debugging convenience.
Returns a string representation of the transactional value in this
instance for debugging convenience. The Ref
reads (and writes)
performed while constructing the result will be discarded before
returning. This method works fine outside a transaction.
If this method is called from within a transaction that is already
doomed (status Txn.Rolledback
), a string describing the reason
for the outer transaction's rollback will be returned.
Returns some value that is suitable for examination in a debugger,
or returns a Txn.RollbackCause
if called from inside a doomed atomic
block.
Returns some value that is suitable for examination in a debugger,
or returns a Txn.RollbackCause
if called from inside a doomed atomic
block.
Source[+A]
consists of the covariant read-only operations ofRef[A]
.