Title: Theory / Unimportant / CS / Programming / Kotlin / Library / Mutex
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html#thread-safe-data-structures

Typ: Mutex
Meaning: A mutex
Page: https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html#thread-safe-data-structures
Language: Kotlin

Instruction: mutex.withLock(
  owner = null,
  fn
)
Effect: wait until lock is available, lock, execute fn and unlock.
Language: Kotlin
Returns: result of action
Variables: Mutex mutex
Exception: IllegaleStateException if lock is already owned by same owner

Instruction: Mutex(locked= false)
Language: Kotlin
Returns: a mutex which is or not locked at creation
Variables: Mutex mutex

Instruction: mutex.holdsLock(owner)
Language: Kotlin
Returns: Whether mutex is hold by owner
Variables: Mutex mutex

Instruction: mutex.lock(owner)
Effect: lock the mutex. Wait until lock is available
Language: Kotlin
Variables: Mutex mutex
Exception: IllegalStateException if already locked by same owner.

Instruction: mutex.tryLock(
owner=null
)
Effect: lock the mutex if possible
Language: Kotlin
Returns: whether lock was acquired
Variables: Mutex mutex
Exception: IllegaleStateException if lock is already owned by same owner

Instruction: mutex.unlock()
Effect: unlock the mutex
Language: Kotlin
Variables: Mutex mutex
Exception: IllegaleStateException if lock is unlock or owned by different owner

Variable: mutex.isLocked
Meaning: whether mutex is locked
Page: https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html#thread-safe-data-structures
Language: Kotlin
Variables: Mutex mutex