AtomicUpdater

trait AtomicUpdater[U, W]
class Object
trait Matchable
class Any

Value members

Concrete methods

@tailrec
final protected def atomicUpdate(f: W => W): W

Recursive, atomic updates. If there is an unguaranteed update of atomicity, it may loop indefinitely.

Recursive, atomic updates. If there is an unguaranteed update of atomicity, it may loop indefinitely.

Value Params
f

Update function.

protected def compareAndSet(o: W, n: W): Boolean

Update only if the existing data is in the expected state. If it is not in the expected state, it will not be updated.

Update only if the existing data is in the expected state. If it is not in the expected state, it will not be updated.

Value Params
n

Update symbol.

o

Expected symbol.

protected def get: W

Returns a new reference that is the result of the snapshot.

Returns a new reference that is the result of the snapshot.

protected def getAndSet(n: W): W

Atomically sets the field of the given object managed by this updater to the given value and returns the old value.

Atomically sets the field of the given object managed by this updater to the given value and returns the old value.

Value Params
n

the new value

Returns

the previous value

protected def getAndUpdate(nf: UnaryOperator[W]): W

Atomically updates the field of the given object managed by this updater with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

Atomically updates the field of the given object managed by this updater with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

Value Params
nf

a side-effect-free function

Returns

the previous value

Since

1.8

protected def getRef: W

Gets the current value held in the field of the given object managed by this updater.

Gets the current value held in the field of the given object managed by this updater.

Returns

the current value

protected def set(n: W): Unit

Sets the field of the given object managed by this updater to the given updated value. This operation is guaranteed to act as a volatile store with respect to subsequent invocations of compareAndSet.

Sets the field of the given object managed by this updater to the given updated value. This operation is guaranteed to act as a volatile store with respect to subsequent invocations of compareAndSet.

Value Params
n

the new value

protected def snapshot(w: W): W

Provides a way to create a snapshot if necessary. Usually not processed.

Provides a way to create a snapshot if necessary. Usually not processed.

In that case, response is a reference, so if you change it, it may affect the value that other threads reference. To prevent this, use snapshot or compareAndSet to override snapshot and update.

 override def snapshot(w: W): W = w.snapshot()

 val old = getRef
 val newRef = get
 newRef.update(x -> y)
 compareAndSet(old, newRef)
Value Params
w

value type

Abstract fields

val updater: AtomicReferenceFieldUpdater[U, W]