AtomicRef
AtomicRef
¶
An object reference that may be updated atomically.
Methods:
-
compare_and_set–Atomically read the current value of this
AtomicRef: -
get–Atomically read the current value of this
AtomicRef. -
get_and_set–Atomically swap the value of this
AtomicReftodesiredand return -
get_handle–Get a thread-local handle for this
AtomicRef. -
set–Unconditionally set the value of this
AtomicReftodesired.
compare_and_set
¶
compare_and_set(expected: T, desired: T) -> bool
Atomically read the current value of this AtomicRef:
- if it is
expected, then replace it withdesiredand returnTrue - else, don't change it and return
False.
get_and_set
¶
Atomically swap the value of this AtomicRef to desired and return
the previously stored value.
get_handle
¶
get_handle() -> ThreadHandle[Self]
Get a thread-local handle for this AtomicRef.
When using a thread-local handle, you can improve the performance of your application.
See ThreadHandle for more
information on thread-local object handles.
set
¶
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.