Module sync/waitgroup
sync/waitgroup
Wait for a group of tasks to complete, similar to Go's sync.WaitGroup.
Example
{ WaitGroup } :: import "std/sync/waitgroup";
{ Thread } :: import "std/thread";
wg := WaitGroup.new();
wg.add(i32(3));
i := i32(0);
while runtime((i < i32(3))), {
t := Thread.spawn(() => {
// ... do work ...
wg.done();
});
i = (i + i32(1));
};
wg.wait(); // blocks until all 3 tasks call done()
Types
WaitGroup
atomic object
WaitGroup
Synchronization primitive that blocks until a counter reaches zero. Uses atomic reference counting for safe cross-thread sharing.
Fields
| Name | Type | Description |
|---|---|---|
_count | i32 | |
_mutex | Mutex | |
_cv | Cond |
impl(WaitGroup, ...)
new : (WaitGroup) fn() -> WaitGroupReturns: WaitGroup
add : (WaitGroup) fn(self : WaitGroup, delta : i32) -> unitdone : (WaitGroup) fn(self : WaitGroup) -> unitwait : (WaitGroup) fn(self : WaitGroup) -> unitcount : (WaitGroup) fn(self : WaitGroup) -> i32