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
| Property | Type |
|---|---|
inner | BarrierInner* |
Constructors
static new(count: u32) -> Barrier;
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;
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
| Property | Type |
|---|---|
is_leader | boolean |
Methods
is_leader(&this) -> boolean;
Trait implementations
implement trait Drop for struct Barrier
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct Barrier {
inner: BarrierInner*;
}Barrier: thread rendezvous point.
Barrier.inner: BarrierInner*type struct BarrierInner {
pthread_buf: [u8;
32];
}static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static Barrier::new(count: u32) -> BarrierConstruct 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).
(parameter) count: u32Barrier::wait(&this) -> BarrierWaitResultBlock 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.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
type struct BarrierWaitResult {
is_leader: boolean;
}Result of Barrier::wait(). Exactly one of the threads at each barrier cycle observes is_leader == true; this is the standard way to designate one thread to do per-phase cleanup work.
type struct BarrierWaitResult {
is_leader: boolean;
}Result of Barrier::wait(). Exactly one of the threads at each barrier cycle observes is_leader == true; this is the standard way to designate one thread to do per-phase cleanup work.
BarrierWaitResult.is_leader: booleanimport a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
Barrier::wait(&this) -> BarrierWaitResultBlock 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.
Barrier.inner: BarrierInner*static Barrier::new(count: u32) -> BarrierConstruct 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).
BarrierWaitResult.is_leader: booleantype trait Send {}Types that are safe to transfer between threads. An owning value of a Send type may cross a thread boundary without violating memory safety.
type trait Sync {}Types that are safe to share between threads by shared reference. T: Sync if &T: Send.
implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language reference