Foundation
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Foundation::Core::ParallelForJob< Fn > Struct Template Referencefinal

Self-draining for-loop job used by ThreadPool::ParallelFor. More...

#include <ThreadPool.hpp>

Inheritance diagram for Foundation::Core::ParallelForJob< Fn >:
Foundation::Core::Job

Public Member Functions

void Execute (size_t workerId) noexcept override
 
- Public Member Functions inherited from Foundation::Core::Job
virtual ~Job ()=default
 

Public Attributes

Fn * fn {nullptr}
 
size_t total {0}
 
Atomic< size_t > cursor {0}
 
Atomic< size_t > remaining {0}
 

Detailed Description

template<typename Fn>
struct Foundation::Core::ParallelForJob< Fn >

Self-draining for-loop job used by ThreadPool::ParallelFor.

One instance is co-invoked across N workers (+ the calling thread) via ThreadPool::CoInvoke; each pulls indices from a shared atomic cursor until the range is exhausted, invoking fn per index. It lives on the caller's stack — no heap allocation, no future. fn is invoked concurrently as fn(i) / fn(i, workerId), so it must be thread-safe: shared captures read-only, writes disjoint per index, any scratch keyed by workerId (a worker never runs two invocations at once, so per-worker scratch is race-free). Per-index granularity is intentional — a job that wants coarser work batches itself by choosing count.

Member Function Documentation

◆ Execute()

template<typename Fn >
void Foundation::Core::ParallelForJob< Fn >::Execute ( size_t  workerId)
inlineoverridevirtualnoexcept

Implements Foundation::Core::Job.

Member Data Documentation

◆ cursor

template<typename Fn >
Atomic<size_t> Foundation::Core::ParallelForJob< Fn >::cursor {0}

◆ fn

template<typename Fn >
Fn* Foundation::Core::ParallelForJob< Fn >::fn {nullptr}

◆ remaining

template<typename Fn >
Atomic<size_t> Foundation::Core::ParallelForJob< Fn >::remaining {0}

◆ total

template<typename Fn >
size_t Foundation::Core::ParallelForJob< Fn >::total {0}

The documentation for this struct was generated from the following file: