Bundle
System support for threads and runtime concurrency
Barrier
Cyclic barrier: each of a fixed number of threads calls Await, and none returns until all of them have arrived. The barrier then resets, so the same threads can meet at it again (a checkpoint per round). A thread that has finished calls Leave, and the rest carry on without it.
Example
class Worker from Thread {
@barrier : Barrier;
New(barrier : Barrier) {
Parent("worker");
@barrier := barrier;
}
method : public : Run(param : System.Base) ~ Nil {
each(round : 3) {
# ... this round's work ...
@barrier->Await(); # wait for every worker to finish the round
};
}
}Operations
Await #
Waits until every party has called Await in this round
method : public : Await() ~ IntReturn
| Type | Description |
|---|---|
| Int | arrival order in this round: 0 for the first thread to arrive, parties - 1 for the last, which releases the others |
GetParties #
Number of threads that meet at the barrier
method : public : GetParties() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of parties |
GetRounds #
Number of rounds completed: how many times every party has met at the barrier
method : public : GetRounds() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of completed rounds |
GetWaiting #
Number of threads waiting at the barrier now
method : public : GetWaiting() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of waiting threads |
Leave #
Leaves the barrier for good: one fewer party meets at it from now on. If every remaining party is already waiting, the round is complete and they are released.
method : public : Leave() ~ Nil