Skip to content

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.

csharp
public sealed class ParallelRunner : IDisposable

Inheritance ​

object ← ParallelRunner

Implements ​

IDisposable

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.

csharp
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.

csharp
public ParallelRunner(int workerCount)

Parameters ​

workerCount int

Properties ​

WorkerCount ​

Number of worker threads (the calling thread also works).

csharp
public int WorkerCount { get; }

Property Value ​

int

Methods ​

Dispose() ​

Stop the worker threads.

csharp
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.

csharp
public void Run<TJob>(TJob job, int count, int chunkSize = 1024) where TJob : struct, IRangeJob

Parameters ​

job TJob

count int

chunkSize int

Type Parameters ​

TJob