Struct Counter

Struct Documentation

struct Counter

Synchronization primitive for fork-join parallelism.

Counter tracks the number of dispatched jobs to enable fork-join synchronization. When jobs are dispatched with a Counter, the counter is automatically incremented. When each job completes, the counter is decremented. wait_for_counter() blocks until the count reaches zero, indicating all jobs have completed.

Example:

Counter counter{};

// Dispatch parallel jobs
for (int i = 0; i < 10; i++)
    scheduler.dispatch_job(process_item(i), JobPriority::Normal, &counter);

// Wait for all jobs to complete
scheduler.wait_for_counter(counter);

See also

Scheduler::dispatch_job for job dispatch with counter

See also

Scheduler::wait_for_counter for synchronization

Note

Counter must outlive all jobs referencing it

Public Members

std::atomic<size_t> count
std::atomic_flag blocking