Table of Contents

Class Dispatcher

Namespace
Stride.Core.Threading
Assembly
Stride.Core.dll
public static class Dispatcher
Inheritance
object
Dispatcher

Properties

MaxDegreeOfParallelism

public static int MaxDegreeOfParallelism { get; set; }

Property Value

int

Methods

ForBatched<TJob>(int, TJob)

The call producing the least amount of overhead, other methods are built on top of this one.

public static void ForBatched<TJob>(int items, TJob batchJob) where TJob : Dispatcher.IBatchJob

Parameters

items int

The amount of items to process, this total will be split into multiple batches, each batch runs TJob.Process(int, int) with the range of items for that batch

batchJob TJob

An object shared across all threads running this job, if TJob is a struct each threads will work off of a unique copy of it

Type Parameters

TJob

Exceptions

Exception

A batch threw: no new batch starts, and the first exception is rethrown in the caller's scope once the running batches end.

ForBatched<TState>(int, TState, Action<TState, int, int>)

Splits items into batches and runs executeBatch on each batch, on multiple threads.

public static void ForBatched<TState>(int items, TState state, Action<TState, int, int> executeBatch)

Parameters

items int

The number of items to process.

state TState

The value passed to each executeBatch call.

executeBatch Action<TState, int, int>

Called with the state and the range of a batch, from inclusive to exclusive.

Type Parameters

TState

Remarks

Use a static lambda and pass what it needs through state, so that the call does not allocate.

ForBatched<T>(int, ref T, delegate*<ref T, int, int, void>)

public static void ForBatched<T>(int items, ref T parameter, delegate*<ref T, int, int, void> executeBatch)

Parameters

items int
parameter T
executeBatch delegate*<ref T, int, int, void>

Type Parameters

T

ForBatched<T>(int, ref T, delegate*<ref T, int, int, void>)

public static void ForBatched<T>(int items, ref T parameter, delegate*<ref T, int, int, void> executeBatch)

Parameters

items int
parameter T
executeBatch delegate*<ref T, int, int, void>

Type Parameters

T

ForEach<T, TState>(IReadOnlyList<T>, TState, Action<TState, T>)

Runs action for each item of collection, on multiple threads.

public static void ForEach<T, TState>(IReadOnlyList<T> collection, TState state, Action<TState, T> action)

Parameters

collection IReadOnlyList<T>

The items to process.

state TState

The value passed to each action call.

action Action<TState, T>

Called with the state and the item.

Type Parameters

T
TState

Remarks

Use a static lambda and pass what it needs through state, so that the call does not allocate.

For<TState>(int, int, TState, Action<TState, int>)

Runs action for each index from fromInclusive to toExclusive, on multiple threads.

public static void For<TState>(int fromInclusive, int toExclusive, TState state, Action<TState, int> action)

Parameters

fromInclusive int

The first index.

toExclusive int

The index after the last one.

state TState

The value passed to each action call.

action Action<TState, int>

Called with the state and the index.

Type Parameters

TState

Remarks

Use a static lambda and pass what it needs through state, so that the call does not allocate.

Sort<T>(FastList<T>, IComparer<T>)

[Obsolete("This method will be removed in the future alongside FastList. We will have an alternative using Span<T> which you will be able to fallback to.")]
public static void Sort<T>(FastList<T> collection, IComparer<T> comparer)

Parameters

collection FastList<T>
comparer IComparer<T>

Type Parameters

T

Sort<T>(ConcurrentCollector<T>, IComparer<T>)

public static void Sort<T>(ConcurrentCollector<T> collection, IComparer<T> comparer)

Parameters

collection ConcurrentCollector<T>
comparer IComparer<T>

Type Parameters

T

Sort<T>(T[], int, int, IComparer<T>)

Sorts a range of collection, splitting a range of more than 2,048 items between threads.

public static void Sort<T>(T[] collection, int index, int length, IComparer<T> comparer)

Parameters

collection T[]
index int
length int
comparer IComparer<T>

Type Parameters

T

Exceptions

InvalidOperationException

comparer threw inside Sort<T>(T[], int, int, IComparer<T>), which sorts every range of at most 2,048 items; the comparer's exception is the inner exception.

Exception

comparer threw while a larger range was split; it is rethrown once the other threads have stopped.

Events

OnMaxDegreeOfParallelismChanged

public static event Action? OnMaxDegreeOfParallelismChanged

Event Type

Action