Counters v0.1.0
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.
Constructors
Semaphore
pub func Semaphore(permits: uint32) -> Semaphore
A semaphore holding permits permits. Running out of memory for it is a program error.
| Name | Type | Description |
|---|---|---|
permits | uint32 | how many permits there are to start with |
Returns: the first handle to it
Methods
Clone
pub func Clone(self: &Semaphore) -> Semaphore
Another handle to the same permits.
Returns: the handle
Acquire
pub func Acquire(self: &Semaphore)
Takes a permit, waiting while none is left.
TryAcquire
pub func TryAcquire(self: &Semaphore) -> bool
Takes a permit if one is left, without waiting.
Returns: whether a permit was taken
Release
pub func Release(self: &Semaphore, count: uint32)
Gives back count permits, waking threads waiting for them.
| Name | Type | Description |
|---|---|---|
count | uint32 | how many permits to give back |
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
Destructor
~Semaphore
func ~Semaphore(self: &var Semaphore)
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.
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.
| Name | Type | Description |
|---|---|---|
parties | uint32 | how many threads each round waits for |
Returns: the first handle to it
Methods
Clone
pub func Clone(self: &Barrier) -> Barrier
Another handle to the same barrier.
Returns: the handle
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
Destructor
~Barrier
func ~Barrier(self: &var Barrier)
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.
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
Methods
Clone
pub func Clone(self: &WaitGroup) -> WaitGroup
Another handle to the same count.
Returns: the handle
Add
pub func Add(self: &WaitGroup, count: uint32)
Adds count pieces of pending work, before the work is started.
| Name | Type | Description |
|---|---|---|
count | uint32 | how many to add |
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.
Wait
pub func Wait(self: &WaitGroup)
Waits until no work is pending.
Destructor
~WaitGroup
func ~WaitGroup(self: &var WaitGroup)