v2026.11.0
All Bundles
Bundle

System support for threads and runtime concurrency

Barrier

Cyclic barrier: each of a fixed number of threads calls Await, and none returns until all of them have arrived. The barrier then resets, so the same threads can meet at it again (a checkpoint per round). A thread that has finished calls Leave, and the rest carry on without it.

Example

class Worker from Thread {
  @barrier : Barrier;

  New(barrier : Barrier) {
    Parent("worker");
    @barrier := barrier;
  }

  method : public : Run(param : System.Base) ~ Nil {
    each(round : 3) {
      # ... this round's work ...
      @barrier->Await(); # wait for every worker to finish the round
    };
  }
}

Operations

Await #

Waits until every party has called Await in this round

method : public : Await() ~ Int

Return

TypeDescription
Intarrival order in this round: 0 for the first thread to arrive, parties - 1 for the last, which releases the others

GetParties #

Number of threads that meet at the barrier

method : public : GetParties() ~ Int

Return

TypeDescription
Intnumber of parties

GetRounds #

Number of rounds completed: how many times every party has met at the barrier

method : public : GetRounds() ~ Int

Return

TypeDescription
Intnumber of completed rounds

GetWaiting #

Number of threads waiting at the barrier now

method : public : GetWaiting() ~ Int

Return

TypeDescription
Intnumber of waiting threads

Leave #

Leaves the barrier for good: one fewer party meets at it from now on. If every remaining party is already waiting, the round is complete and they are released.

method : public : Leave() ~ Nil

New # constructor

Creates a barrier

New(parties:Int)

Parameters

NameTypeDescription
partiesIntnumber of threads that meet at the barrier (at least 1)