CyclicBarrier
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
.
Parameters
The number of coroutines that must await until the barrier cycles and all are released.
An optional runnable that will be executed when the barrier is cycled, but before releasing.
Functions
When called, all waiting coroutines will be cancelled with CancellationException. When all coroutines have been cancelled the barrier will cycle.