Stm Semaphore
STM-based semaphore for concurrency limiting using transactional memory.
Unlike mutex-based semaphores, STM semaphores can be composed with other transactional operations atomically.
Basic usage:
val sem = StmSemaphore.create(5)
val acquired = atomically { with(sem) { acquire() } } // true
println(sem.availablePermits()) // 4
atomically { with(sem) { release() } }
println(sem.availablePermits()) // 5Content copied to clipboard
Composing with state machine:
val sem = StmSemaphore.create(3)
val sm = StmStateMachine.create(State.IDLE)
atomically {
val acquired = with(sem) { acquire() }
if (acquired) {
with(sm) { transition(State.RUNNING) }
}
}Content copied to clipboard
Types
Link copied to clipboard
object Companion
Factory for StmSemaphore.