Skip to content

AtomicRef

An object reference that may be updated atomically.

__init__(initial_value=None)

compare_and_set(expected, desired)

Atomically read the current value of this AtomicRef:

  • if it is expected, then replace it with desired and return True
  • else, don't change it and return False.

get()

Atomically read the current value of this AtomicRef.

get_and_set(desired)

Atomically swap the value of this AtomicRef to desired and return the previously stored value.

set(desired)

Unconditionally set the value of this AtomicRef to desired.

Warning

Use compare_and_set instead.

When using this method, it is not possible to know that the value currently stored is the one being expected -- it may be mutated by another thread before this mutation is applied. Use this method only when no other thread may be writing to this AtomicRef.