Skip to content

Queue Type

ZjzMisaka edited this page Dec 19, 2025 · 12 revisions

FIFO | LIFO | Deque

By setting the QueueType, you can determine whether the thread pool will operate in a first-in-first-out (FIFO) or last-in-first-out (LIFO) or Deque manner to meet various business requirements.
Default is FIFO.

powerPool.PowerPoolOption = new PowerPoolOption()
{
    QueueType = QueueType.LIFO,
};

Custom

If PowerPoolOption.CustomQueueFactory is set, regardless of whether QueueType is set or not, PowerThreadPool will use instances of the custom queue type to manage work items.
The custom queue type must inherit from the IStealablePriorityCollection<WorkItemBase> interface.

Properties

Indicates whether the pool enforces the deque ownership discipline (owner-only bottom ops, others steal from top).
If you use a custom queue that follows the convention of having an owner thread for the deque, set EnforceDequeOwnership to true during constructor initialization.

bool EnforceDequeOwnership { get; }

Functions

Sets an item with a specified priority in the collection.

void Set(T item, int priority);

Retrieves and removes the highest priority item from the collection.
The method is typically called by the owner thread to fetch the next work.

T Get();

Steals and removes the highest priority item from the collection.
This method is typically called by other threads to steal work from the owner thread.

T Steal();

Discard the lowest priority item from the collection.

T Discard();

Clone this wiki locally