SynchronizedObject

expect open class SynchronizedObject

SynchronizedObject from kotlinx.atomicfu.locks

SynchronizedObject is designed for inheritance. You write class MyClass : SynchronizedObject() and then use synchronized(instance) { ... } extension function similarly to the synchronized function from the standard library that is available for JVM. The SynchronizedObject superclass gets erased (transformed to Any) on JVM and JS, with synchronized leaving no trace in the code on JS and getting replaced with built-in monitors for locking on JVM.

actual typealias SynchronizedObject = Any

SynchronizedObject from kotlinx.atomicfu.locks

SynchronizedObject is designed for inheritance. You write class MyClass : SynchronizedObject() and then use synchronized(instance) { ... } extension function similarly to the synchronized function from the standard library that is available for JVM. The SynchronizedObject superclass gets erased (transformed to Any) on JVM and JS, with synchronized leaving no trace in the code on JS and getting replaced with built-in monitors for locking on JVM.

actual typealias SynchronizedObject = Any

SynchronizedObject from kotlinx.atomicfu.locks

SynchronizedObject is designed for inheritance. You write class MyClass : SynchronizedObject() and then use synchronized(instance) { ... } extension function similarly to the synchronized function from the standard library that is available for JVM. The SynchronizedObject superclass gets erased (transformed to Any) on JVM and JS, with synchronized leaving no trace in the code on JS and getting replaced with built-in monitors for locking on JVM.

actual open class SynchronizedObject

SynchronizedObject from kotlinx.atomicfu.locks

SynchronizedObject is designed for inheritance. You write class MyClass : SynchronizedObject() and then use synchronized(instance) { ... } extension function similarly to the synchronized function from the standard library that is available for JVM. The SynchronizedObject superclass gets erased (transformed to Any) on JVM and JS, with synchronized leaving no trace in the code on JS and getting replaced with built-in monitors for locking on JVM.

Constructors

Link copied to clipboard
expect constructor()
constructor()

Functions

Link copied to clipboard
fun lock()

Acquires the lock. If the lock is already held by another thread, the current thread will block until it can acquire the lock.

Link copied to clipboard

Attempts to acquire the lock. If the lock is available, it will be acquired, and this function will return true. If the lock is already held by another thread, this function will return false immediately without blocking.

Link copied to clipboard
fun unlock()

Releases the lock. If the current thread holds the lock, it will be released, allowing other threads to acquire it.