CyclicBarrier

class CyclicBarrier(val capacity: Int)(source)

A CyclicBarrier is a synchronization mechanism that allows a set of coroutines to wait for each other to reach a certain point before continuing execution. It is called a "cyclic" barrier because it can be reused after all coroutines have reached the barrier and released.

To use a CyclicBarrier, each coroutine must call the await method on the barrier object, which will cause the coroutine to suspend until the required number of coroutines have reached the barrier. Once all coroutines have reached the barrier they will resume execution.

Models the behavior of java.util.concurrent.CyclicBarrier in Kotlin with suspend.

Constructors

Link copied to clipboard
fun CyclicBarrier(capacity: Int)

Functions

Link copied to clipboard
suspend fun await()

When await is called the function will suspend until the required number of coroutines have reached the barrier. Once the capacity of the barrier has been reached, the coroutine will be released and continue execution.

Properties

Link copied to clipboard