ReentrantLock

expect class ReentrantLock

ReentrantLock from kotlinx.atomicfu.locks

ReentrantLock is designed for delegation. You write val lock = reentrantLock() to construct its instance and use lock/tryLock/unlock functions or lock.withLock { ... } extension function similarly to the way jucl.ReentrantLock is used on JVM. On JVM it is a typealias to the later class, erased on JS.

actual class ReentrantLock

ReentrantLock from kotlinx.atomicfu.locks

ReentrantLock is designed for delegation. You write val lock = reentrantLock() to construct its instance and use lock/tryLock/unlock functions or lock.withLock { ... } extension function similarly to the way jucl.ReentrantLock is used on JVM. On JVM it is a typealias to the later class, erased on JS.

ReentrantLock from kotlinx.atomicfu.locks

ReentrantLock is designed for delegation. You write val lock = reentrantLock() to construct its instance and use lock/tryLock/unlock functions or lock.withLock { ... } extension function similarly to the way jucl.ReentrantLock is used on JVM. On JVM it is a typealias to the later class, erased on JS.

ReentrantLock from kotlinx.atomicfu.locks

ReentrantLock is designed for delegation. You write val lock = reentrantLock() to construct its instance and use lock/tryLock/unlock functions or lock.withLock { ... } extension function similarly to the way jucl.ReentrantLock is used on JVM. On JVM it is a typealias to the later class, erased on JS.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
expect 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.

actual inline fun lock()
Link copied to clipboard
expect fun tryLock(): Boolean

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.

actual inline fun tryLock(): Boolean
Link copied to clipboard
expect fun unlock()

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

actual inline fun unlock()
Link copied to clipboard
expect inline fun <T> ReentrantLock.withLock(block: () -> T): T

Executes the given block of code while holding the specified ReentrantLock. This function simplifies the process of acquiring and releasing a lock safely.

actual inline fun <T> ReentrantLock.withLock(block: () -> T): T

Executes the given block of code while holding the specified ReentrantLock. This function simplifies the process of acquiring and releasing a lock safely.