ParallelJobRunner.md
July 25, 2024 · View on GitHub
Friflo.Engine.ECS
Friflo.Engine.ECS
ParallelJobRunner Class
Required for parallel - multi threaded - query job execution using RunParallel().
See Example.
public sealed class ParallelJobRunner :
System.IDisposable
Inheritance System.Object 🡒 ParallelJobRunner
Implements System.IDisposable
Remarks
ParallelJobRunner is thread safe.
The intention is to use the same instance for all jobs. E.g. the JobRunner assigned to the EntityStore.
The job runner divide a job in multiple tasks each executed on its own core.
This ensures high cache hit rate of code and data structures.
Constraint
When executing nested jobs - running a job within another job - the nested job requires its own runner.
Performance related implementation goals:
- Minimize calls to synchronization primitives.
- Use cheap synchronization primitives such as:
System.Threading.ManualResetEventSlim, System.Threading.Interlocked and System.Threading.Volatile.
- Minimize thread context switches caused by System.Threading.ManualResetEventSlim in case calling
System.Threading.ManualResetEventSlim.Wait when the event is not signaled.
Note: To analyze the amount of thread context switches use: Process Explorer > Column > CSwitch Delta.
| Constructors | |
|---|---|
| ParallelJobRunner(int, string) |
| Properties | |
|---|---|
| IsDisposed | |
| ThreadCount |
| Methods | |
|---|---|
| Dispose() | |
| ToString() |