Norbi
01/17/2024, 12:05 PMatomic(...)
to a local variable (which is later passed to a lambda)?
* Refrain from invoking atomic operations on local variables:
```
val top = atomic<Node?>(null)
val tmp = top
tmp.compareAndSet(null, Node(1)) // DON'T DO THIS
```Thanks.
Sam
01/17/2024, 1:04 PMAtomic<T>
will actually be transformed into a plain T
, and access to it will be turned into direct atomic updates of the underlying field. In other words, at runtime, the Atomic
object itself is gone. So you can't pass it around between different variables and functions.Norbi
01/17/2024, 1:11 PMAtomicReference
, AtomicInteger
, etc. 😮Sam
01/17/2024, 1:12 PMan atomic value is represented as a plain value atomically updated withfrom the Java standard library.java.util.concurrent.atomic.AtomicXxxFieldUpdater
Sam
01/17/2024, 1:13 PMAtomicReference
instead