Table of Contents

Class CpuThreadPool

Namespace
DotCompute.Backends.CPU.Threading
Assembly
DotCompute.Backends.CPU.dll

High-performance thread pool optimized for CPU compute workloads with work-stealing support.

public sealed class CpuThreadPool : IAsyncDisposable
Inheritance
CpuThreadPool
Implements
Inherited Members

Constructors

CpuThreadPool(IOptions<CpuThreadPoolOptions>)

Initializes a new instance of the CpuThreadPool class.

public CpuThreadPool(IOptions<CpuThreadPoolOptions> options)

Parameters

options IOptions<CpuThreadPoolOptions>

The options.

Properties

MaxConcurrency

Gets the maximum concurrency level (number of worker threads). This is an alias for WorkerCount for compatibility.

public int MaxConcurrency { get; }

Property Value

int

WorkerCount

Gets the number of worker threads.

public int WorkerCount { get; }

Property Value

int

Methods

DisposeAsync()

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

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

EnqueueAsync(Action, CancellationToken)

Enqueues work to be executed on the thread pool.

public ValueTask EnqueueAsync(Action work, CancellationToken cancellationToken = default)

Parameters

work Action
cancellationToken CancellationToken

Returns

ValueTask

EnqueueAsync<T>(Func<T>, CancellationToken)

Enqueues work and returns a task that completes when the work is done.

public ValueTask<T> EnqueueAsync<T>(Func<T> work, CancellationToken cancellationToken = default)

Parameters

work Func<T>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

EnqueueBatchAsync(IEnumerable<Action>, CancellationToken)

Enqueues multiple work items for batch processing.

public ValueTask EnqueueBatchAsync(IEnumerable<Action> workItems, CancellationToken cancellationToken = default)

Parameters

workItems IEnumerable<Action>
cancellationToken CancellationToken

Returns

ValueTask

GetStatistics()

Gets statistics about the thread pool.

public ThreadPoolStatistics GetStatistics()

Returns

ThreadPoolStatistics