Table of Contents

Class ThreadPool

Namespace
Stride.Core.Threading
Assembly
Stride.Core.dll

Thread pool for scheduling sub-millisecond actions, do not schedule long-running tasks. Can be instantiated and generates less garbage than dotnet's.

public sealed class ThreadPool : IDisposable
Inheritance
ThreadPool
Implements
Extension Methods

Constructors

ThreadPool(int?)

public ThreadPool(int? threadCount = null)

Parameters

threadCount int?

Fields

Instance

The default instance that the whole process shares, use this one to avoid wasting process memory.

public static ThreadPool Instance

Field Value

ThreadPool

WorkerThreadsCount

Amount of threads within this pool

public readonly int WorkerThreadsCount

Field Value

int

Properties

CompletedWork

Amount of work completed

public ulong CompletedWork { get; }

Property Value

ulong

IsWorkedThread

Is the thread reading this property a worker thread

public static bool IsWorkedThread { get; }

Property Value

bool

ThreadsBusy

Amount of threads currently executing work items

public int ThreadsBusy { get; }

Property Value

int

WorkScheduled

Amount of work waiting to be taken care of

public int WorkScheduled { get; }

Property Value

int

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

QueueUnsafeWorkItem(object, delegate*<object, void>, int)

Queue some work item to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond. Additionally, the parameter provided must be fixed from this call onward until the action has finished executing

public void QueueUnsafeWorkItem(object parameter, delegate*<object, void> obj, int amount = 1)

Parameters

parameter object
obj delegate*<object, void>
amount int

QueueWorkItem(Action, int)

Queue an action to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond.

public void QueueWorkItem(Action workItem, int amount = 1)

Parameters

workItem Action
amount int

TryCooperate()

Attempt to steal work from the threadpool to execute it from the calling thread. If you absolutely have to block inside one of the threadpool's thread for whatever reason do a busy loop over this function.

public bool TryCooperate()

Returns

bool