MutexLock

A MutexLock is a locking mechanism which allows only one thread to gain access to a resource protected by an instance of MutexLock. If more than one thread tries to acquire lock, only the first thread is successful while the other threads either wait or return depending on whether lock or tryLock was invoked.

Examples

val mutex = MutexLock()
mutex.lock()
assertFalse(mutex.tryLock())
val future = WorkerFactory.newBackgroundWorker().execute(mutex) {
assertFalse(mutex.tryLock())
}
future.await()
mutex.unlock()
mutex.destroy()

class MutexLock
class MutexLock

Constructors

MutexLock
Link copied to clipboard
common
fun MutexLock()

Functions

destroy
Link copied to clipboard

Releases any memory resources. The instance should be discarded after calling this method.

common
fun destroy()
ios
fun destroy()
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
lock
Link copied to clipboard

Acquires a lock on the mutex. If the lock is already acquired by another thread, then the subsequent callers of this method are blocked until the lock is released.

common
fun lock()
ios
fun lock()
toString
Link copied to clipboard
common
open override fun toString(): String
tryLock
Link copied to clipboard

Tries to acquire a lock on the mutex. If the lock is already acquired by another thread, this method returns immediately with a false value. Otherwise, if the lock is obtained, this method returns true.

common
fun tryLock(): Boolean
ios
fun tryLock(): Boolean
unlock
Link copied to clipboard

Releases an acquired lock on the mutex. This method may throw a RuntimeException depending on the platform.

common
fun unlock()
ios
fun unlock()