← Lessons

quiz vs the machine

Gold1450

Concurrency

The Cyclic Barrier

A reusable barrier that resets after each round so threads can synchronize repeatedly.

5 min read · core · beat Gold to climb

A barrier you can reuse

A plain barrier or countdown latch fires once. A cyclic barrier automatically resets after every group rendezvous, so the same set of threads can synchronize round after round.

How a round works

  • Threads arrive and wait until the party size is reached.
  • An optional barrier action runs once, on the last arriving thread, before release.
  • The barrier resets its count and releases everyone for the next round.

This fits iterative algorithms where each pass must complete before the next begins, such as a parallel solver that exchanges boundary data between iterations.

Generations and failure

Each cycle is a generation. If one waiting thread is interrupted or times out, the barrier breaks the current generation and signals all the others with an exception, so no one is left stranded believing the round succeeded.

Key idea

A cyclic barrier rendezvous a fixed group, optionally runs a one time action, then resets for the next generation, making it the right tool for repeated phase synchronization in iterative work.

Check yourself

Answer to earn rating on the learn ladder.

1. What distinguishes a cyclic barrier from a one shot barrier?

2. When does the optional barrier action run?

3. What happens to a generation if a waiting thread is interrupted?