ReadWriteLock

A ReadWrite lock allows multiple readers to read a value and only one writer to update it. A read lock cannot be obtained until write lock is released. A write lock cannot be obtained until current readers don't release read lock.

Examples

val lock = ReadWriteLock()

// read from multiple threads simultaneously.
lock.acquireReadLock() // call from as many threads

// perform read ....

lock.releaseReadLock()

// to protect writes
lock.acquireWriteLock() // only one thread will get lock, others will be blocked.

// perform write ....

lock.releaseWriteLock() // next thread will now unblock.

class ReadWriteLock
class ReadWriteLock

Constructors

ReadWriteLock
Link copied to clipboard
common
fun ReadWriteLock()

Functions

acquireReadLock
Link copied to clipboard

Acquire a read lock. This method will not return until the lock is acquired.

common
fun acquireReadLock()
ios
fun acquireReadLock()
acquireWriteLock
Link copied to clipboard

Acquires the write lock. This method waits until all readers have released the read lock. It then acquires the write lock and returns.

common
fun acquireWriteLock()
ios
fun acquireWriteLock()
destroy
Link copied to clipboard

Destroys the lock and frees up the memory. After calling this method, the instance can no longer be used.

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

Releases the read lock

common
fun releaseReadLock()
ios
fun releaseReadLock()
releaseWriteLock
Link copied to clipboard

Releases the write lock

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