https://github.com/zjzmisaka/powerthreadpool
A comprehensive and efficient lock-free thread pool with granular work control, flexible concurrency, and robust error handling, alongside an easy-to-use API for diverse work submissions.
https://github.com/zjzmisaka/powerthreadpool
async coroutine csharp dotnet lock-free lockfree task thread thread-pool threadpool
Last synced: 24 days ago
JSON representation
A comprehensive and efficient lock-free thread pool with granular work control, flexible concurrency, and robust error handling, alongside an easy-to-use API for diverse work submissions.
- Host: GitHub
- URL: https://github.com/zjzmisaka/powerthreadpool
- Owner: ZjzMisaka
- License: mit
- Created: 2023-08-25T07:07:45.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-16T08:54:31.000Z (24 days ago)
- Last Synced: 2025-05-16T14:04:54.677Z (24 days ago)
- Topics: async, coroutine, csharp, dotnet, lock-free, lockfree, task, thread, thread-pool, threadpool
- Language: C#
- Homepage: https://www.nuget.org/packages/PowerThreadPool/
- Size: 1.08 MB
- Stars: 139
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# PowerThreadPool





[](https://app.codecov.io/gh/ZjzMisaka/PowerThreadPool)
[](https://www.codefactor.io/repository/github/zjzmisaka/powerthreadpool)A comprehensive and efficient lock-free thread pool with granular work control, flexible concurrency, and robust error handling, alongside an easy-to-use API for diverse work submissions.
## Documentation
Access the Wiki in [English](https://github.com/ZjzMisaka/PowerThreadPool/wiki) | [中文](https://github.com/ZjzMisaka/PowerThreadPool.zh-CN.Wiki/wiki) | [日本語](https://github.com/ZjzMisaka/PowerThreadPool.ja-JP.Wiki/wiki).
Visit the [DeepWiki](https://deepwiki.com/ZjzMisaka/PowerThreadPool) for more information.## Installation
If you want to include PowerThreadPool in your project, you can [install it directly from NuGet](https://www.nuget.org/packages/PowerThreadPool/).
Support: Net40+ | Net5.0+ | netstandard2.0+## Features
- [Pool Control | Work Control](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control)
- [Stop](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#pause-resume-stop)
- [Pause](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#pause-resume-stop)
- [Resume](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#pause-resume-stop)
- [Force Stop](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#force-stop)
- [Wait](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#wait)
- [Fetch](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#fetch)
- [Cancel](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Control#cancel)
- [Thread Pool Sizing](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Thread-Pool-Sizing)
- [Idle Thread Scheduled Destruction](https://github.com/ZjzMisaka/PowerThreadPool/wiki/DestroyThreadOption)
- [Thread Starvation Countermeasures (Long-running Work Support)](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Thread-Pool-Sizing#thread-starvation)
- [Work Callback | Default Callback](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Callback)
- [Rejection Policy](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Rejection-Policy)
- [Parallel Execution](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Parallel-Execution)
- [For](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Parallel-Execution#For)
- [ForEach](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Parallel-Execution#ForEach)
- [Watch](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Parallel-Execution#Watch)
- [Work Priority | Thread Priority](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Priority)
- [Error Handling](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Error-Handling)
- [Retry](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Retry)
- [Work Timeout | Cumulative Work Timeout](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Timeout)
- [Work Dependency](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Dependency)
- [Work Group](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Group)
- [Group Control](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Work-Group#group-control)
- [Group Relation](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Group-Relation)
- [Events](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Events)
- [Runtime Status](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Runtime-Status)
- [Running Timer](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Running-Timer)
- [Queue Type (FIFO | LIFO | Custom)](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Queue-Type)
- [Load Balancing](https://en.wikipedia.org/wiki/Work_stealing)
- [Lock-Free](https://en.wikipedia.org/wiki/Non-blocking_algorithm)## Getting started
### Simple example: run a work
```csharp
PowerPool powerPool = new PowerPool();
powerPool.QueueWorkItem(() =>
{
// Do something
});
```### With callback
```csharp
PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() =>
{
// Do something
return result;
}, (res) =>
{
// Callback of the work
});
```### With option
```csharp
PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() =>
{
// Do something
return result;
}, new WorkOption()
{
// Some options
});
```### Reference
``` csharp
string QueueWorkItem(Action action, T1 param1, ..., *);
string QueueWorkItem(Action action, *);
string QueueWorkItem(Action action, object[] param, *);
string QueueWorkItem(Func function, T1 param1, ..., *);
string QueueWorkItem(Func function, *);
string QueueWorkItem(Func function, object[] param, *);
```
- Asterisk (*) denotes an optional parameter, either a WorkOption or a delegate (`Action>` or `Action>`), depending on whether the first parameter is an Action or a Func.
- In places where you see ellipses (...), you can provide up to five generic type parameters.## More
[Testing And Performance Analysis](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Testing-And-Performance-Analysis) | [Feature Comparison](https://github.com/ZjzMisaka/PowerThreadPool/wiki/Feature-Comparison)