Skip to content
FutureBlitz

    Install

    Import std.concurrent.locks

    Barrier

    std.concurrent.locks

    class

    Public Shared Class Barrier

    Where a number of threads meet, round after round: each one's Wait returns once they've all come, which starts the next round.

    Examples

    Global lasts = Atomic<Int>(0)
    Const meet = Barrier(2)
    
    Function Arrive()
        If meet.Wait() Then lasts.Add(1)
    End Function
    
    Local other = Spawn(Arrive)
    Arrive()
    other.Wait()
    // One of the two is the round's last.
    Expect(lasts.Load() == 1)

    std/concurrent/locks.fb, line 124

    • @PanicsAtCaller Public New(count: Int) constructor #

      A Barrier that count threads meet at each round. Panics unless that's 1 or more.

    • Public Method Wait(): Bool method #

      Waits until the round's last thread comes, and then they all go on. Gives True to that last one, and False to the others, so one of them can do what's done once a round.

    • Public Property Count: Int property #

      How many threads meet at it each round.

    Report an issue with this page or with FutureBlitz on GitHub.