İçeriğe geç

Coroutine'de paylaşılan değiştirilebilir durum (ARCH8038)

Anahtar kotlin.async.shared-mutable-state-in-coroutine · Önem warning · Kategori async

object ya da companion üzerinde bildirilen ve coroutine / iş parçacıklarının @Volatile, atomik ya da Mutex olmadan yazdığı var’ları işaretler.

object Counter { var hits = 0 }
launch { Counter.hits++ }
object Counter { val hits = AtomicInteger() }
launch { Counter.hits.incrementAndGet() }

AtomicInteger / AtomicReference, Mutex kullanın ya da durumu tek coroutine’e hapsedin.