Package kotlinx.coroutines.experimental.sync

Platform and version requirements: JVM

Synchronization primitives (mutex).

Types

Mutex

interface Mutex

Mutual exclusion for coroutines.

Functions

Mutex

fun Mutex(locked: Boolean = false): Mutex

Creates new Mutex instance. The mutex created is fair: lock is granted in first come, first served order.

withLock

suspend fun <T> Mutex.withLock(
    owner: Any? = null,
    action: () -> T
): T

Executes the given action under this mutex’s lock.