Class ParallelRunner
Namespace: KenseiECS
Runs an IRangeJob over a range on a fixed set of worker threads plus the calling thread. No allocations per Run after the first call for a job type.
Rules for jobs: read and write component data only for the entities in the range; no Add/Remove/Create/Destroy, no filter or group registration, no world event listeners — those are single-threaded. Two jobs must not run at the same time on one runner. Exceptions thrown by a worker are rethrown on the calling thread after every chunk finished.
With zero workers (single-core machines, WebGL) Run executes inline.
public sealed class ParallelRunner : IDisposableInheritance
Implements
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Constructors
ParallelRunner()
Create a runner with one worker per logical processor, minus the calling thread.
public ParallelRunner()ParallelRunner(int)
Create a runner with the given number of background worker threads. Zero runs every job inline on the calling thread; a negative count throws ArgumentOutOfRangeException.
public ParallelRunner(int workerCount)Parameters
workerCount int
Properties
WorkerCount
Number of worker threads (the calling thread also works).
public int WorkerCount { get; }Property Value
Methods
Dispose()
Stop the worker threads.
public void Dispose()Run<TJob>(TJob, int, int)
Execute job over [0, count) in chunks of at most chunkSize indices. Chunks are handed out dynamically, so uneven work balances itself.
public void Run<TJob>(TJob job, int count, int chunkSize = 1024) where TJob : struct, IRangeJobParameters
job TJob
count int
chunkSize int
Type Parameters
TJob
