runConcurrently

fun runConcurrently(threadCount: Int, timeout: Duration = 10.seconds, action: (threadIndex: Int) -> Unit)(source)

Runs action concurrently on threadCount real background threads. Blocks the calling thread until every thread returns or timeout elapses.

Threads wait at a barrier until all of them have started, then start together. This maximizes contention on shared state, which is what exposes real races and deadlocks.

A Throwable raised by action on any thread is captured instead of crashing that thread. It is re-thrown from this function once every thread finishes. Extra failures are attached via Throwable.addSuppressed.

Throws

if a thread is still running when timeout elapses. This usually means a deadlock.