Skip to content
CryoCryo home
Stdlibsync

barrier

import std::sync::barrier; · source

Types

Barrier

type struct Barrier {
    inner: BarrierInner*;

    static new(count: u32) -> Barrier;
    wait(&this) -> BarrierWaitResult;
}

A rendezvous for a fixed group of threads. Every thread calling wait() blocks until exactly count have arrived, then all proceed.

Properties

PropertyType
innerBarrierInner*

Constructors

static new(count: u32) -> Barrier;

Construct a barrier that requires count threads before releasing them. Panics on allocation failure or pthread init failure (a non-zero count is the only requirement).

Methods

wait(&this) -> BarrierWaitResult;

Block the current thread until every thread participating in the barrier has called wait(). Returns a BarrierWaitResult whose is_leader flag is true on exactly one of the awakening threads. The barrier is automatically reset for the next cycle once all waiters resume.

BarrierWaitResult

type struct BarrierWaitResult {
    is_leader: boolean;

    is_leader(&this) -> boolean;
}

wait() returns a BarrierWaitResult whose is_leader() is true on exactly one of the awakening threads. That flag is the standard way to designate one thread to do per-phase cleanup after every worker finishes a phase.

The barrier resets automatically for the next cycle. Barrier is Send + Sync unconditionally.

Properties
PropertyType
is_leaderboolean
Methods
is_leader(&this) -> boolean;

Trait implementations

implement trait Drop for struct Barrier