$ show ZjzMisaka/PowerThreadPool
PowerThreadPool is a high-performance .NET thread pool library designed for managing both synchronous and asynchronous workloads with granular control. It implements a low-contention thread pool using work-stealing priority queues, lock-free synchronization primitives, and sophisticated state management for workers and work items. The library provides features like work dependency tracking, group-based operations, pause/resume/cancel controls, timeout/retry policies, and event-driven monitoring. Architecture centers around the PowerPool class managing Worker instances that execute work from concurrent collections, with async support via custom synchronization contexts. Entry points include QueueWorkItem overloads for submitting work and control methods like Start/Stop/Pause/Resume. The library targets .NET Framework 4.0+ through .NET 5+ and netstandard, demonstrating careful backward compatibility through conditional compilation.
The LLM identified 4 files worth highlighting for reuse:
Implements a lock-free, priority-based work-stealing deque adapted from the Chase-Lev algorithm. Enables efficient distribution of work items among worker threads with minimal contention, supporting both priority-based ordering and work stealing for load balancing. Self-contained and reusable in any concurrent scenario requiring a high-performance queue with stealing capabilities.
Provides an atomic flag using Interlocked.CompareExchange for efficient state transitions without locks. A fundamental building block for lock-free data structures and state machines, offering minimal overhead and high performance in concurrent environments. Demonstrates skill in low-level synchronization primitives with clear, concise implementation.
An asynchronous manual reset event that integrates with async/await without blocking threads. Allows waiting for a signal to be set and supports resetting the state. Ideal for coordinating asynchronous operations in a non-blocking manner, replacing traditional ManualResetEvent in async contexts. Self-contained with zero external dependencies beyond .NET primitives.
Encapsulates a timer for executing a single delayed action with built-in cancellation support. Simplifies the management of System.Threading.Timer by encapsulating the timer lifecycle and providing a clean API for scheduling and canceling delayed actions, reducing boilerplate and potential resource leaks. Demonstrates proper resource disposal patterns and callback safety.