Counters v0.1.0

Source
Semaphores, barriers and wait groups.

Semaphore

pub struct Semaphore {
    // private fields
}

A count of permits that threads take and give back, waiting while none is left. Clone gives another handle to the same permits. A handle is not copied.

Source

Constructors

Semaphore

pub func Semaphore(permits: uint32) -> Semaphore

A semaphore holding permits permits. Running out of memory for it is a program error.

NameTypeDescription
permitsuint32how many permits there are to start with

Returns: the first handle to it

Source

Methods

Clone

pub func Clone(self: &Semaphore) -> Semaphore

Another handle to the same permits.

Returns: the handle

Source

Acquire

pub func Acquire(self: &Semaphore)

Takes a permit, waiting while none is left.

Source

TryAcquire

pub func TryAcquire(self: &Semaphore) -> bool

Takes a permit if one is left, without waiting.

Returns: whether a permit was taken

Source

Release

pub func Release(self: &Semaphore, count: uint32)

Gives back count permits, waking threads waiting for them.

NameTypeDescription
countuint32how many permits to give back

Source

Available

pub func Available(self: &Semaphore) -> uint32

The permits left right now, which other threads may change at any moment.

Returns: the number of permits

Source

Destructor

~Semaphore

func ~Semaphore(self: &var Semaphore)

Source

Barrier

pub struct Barrier {
    // private fields
}

A meeting point a fixed number of threads wait at until all of them have arrived, then pass together. The barrier is reusable: once all have passed, the next Waits start a new round. Clone gives another handle to the same barrier. A handle is not copied.

Source

Constructors

Barrier

pub func Barrier(parties: uint32) -> Barrier

A barrier for parties threads. Zero parties is a program error. Running out of memory is one too.

NameTypeDescription
partiesuint32how many threads each round waits for

Returns: the first handle to it

Source

Methods

Clone

pub func Clone(self: &Barrier) -> Barrier

Another handle to the same barrier.

Returns: the handle

Source

Wait

pub func Wait(self: &Barrier) -> bool

Waits until every party of this round has arrived.

Returns: true on exactly one of the round's threads, the last to arrive, for work done once per round

Source

Destructor

~Barrier

func ~Barrier(self: &var Barrier)

Source

WaitGroup

pub struct WaitGroup {
    // private fields
}

A count of unfinished work that threads add to and mark done, and that others wait to see reach zero. Clone gives another handle to the same count. A handle is not copied.

Source

Constructors

WaitGroup

pub func WaitGroup() -> WaitGroup

A wait group with nothing pending. Running out of memory for it is a program error.

Returns: the first handle to it

Source

Methods

Clone

pub func Clone(self: &WaitGroup) -> WaitGroup

Another handle to the same count.

Returns: the handle

Source

Add

pub func Add(self: &WaitGroup, count: uint32)

Adds count pieces of pending work, before the work is started.

NameTypeDescription
countuint32how many to add

Source

Done

pub func Done(self: &WaitGroup)

Marks one piece of work done, waking the waiters when it was the last. Marking more done than were added is a program error.

Source

Wait

pub func Wait(self: &WaitGroup)

Waits until no work is pending.

Source

Destructor

~WaitGroup

func ~WaitGroup(self: &var WaitGroup)

Source