ThreadPool Class
Namespace: Stride.Core.ThreadingAssembly: 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
Name | Description | |
---|---|---|
Constructors | ||
ThreadPool(Nullable<Int32>) | ||
Fields | ||
Instance | The default instance that the whole process shares, use this one to avoid wasting process memory. |
|
WorkerThreadsCount | Amount of threads within this pool |
|
Properties | ||
CompletedWork | Amount of work completed |
|
IsWorkedThread | Is the thread reading this property a worker thread |
|
ThreadsBusy | Amount of threads currently executing work items |
|
WorkScheduled | Amount of work waiting to be taken care of |
|
Methods | ||
Dispose() | ||
QueueWorkItem(Action, Int32) | Queue an action to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond. |
|
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. |
Constructors
ThreadPool(Nullable<Int32>)
public ThreadPool(int? threadCount = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32> | threadCount |
Fields
Instance
The default instance that the whole process shares, use this one to avoid wasting process memory.
public static ThreadPool Instance
Field Value
Type | Description |
---|---|
ThreadPool |
WorkerThreadsCount
Amount of threads within this pool
public readonly int WorkerThreadsCount
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
CompletedWork
Amount of work completed
public ulong CompletedWork { get; }
Property Value
Type | Description |
---|---|
System.UInt64 |
IsWorkedThread
Is the thread reading this property a worker thread
public static bool IsWorkedThread { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ThreadsBusy
Amount of threads currently executing work items
public int ThreadsBusy { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
WorkScheduled
Amount of work waiting to be taken care of
public int WorkScheduled { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Dispose()
public void Dispose()
QueueWorkItem(Action, Int32)
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
Type | Name | Description |
---|---|---|
System.Action | workItem | |
System.Int32 | amount |
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
Type | Description |
---|---|
System.Boolean |