Shared Mutable State In Coroutine (ARCH8038)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key kotlin.async.shared-mutable-state-in-coroutine · Severity warning · Category async
Flags a var declared on an object or companion that coroutines / threads write to without @Volatile, an atomic or a Mutex.
Incorrect
Section titled “Incorrect”object Counter { var hits = 0 }launch { Counter.hits++ }Correct
Section titled “Correct”object Counter { val hits = AtomicInteger() }launch { Counter.hits.incrementAndGet() }Use AtomicInteger / AtomicReference, a Mutex, or confine the state to one coroutine.