https://github.com/mp81ss/ctp
C-Thread-Pool, the universal thread pool library
https://github.com/mp81ss/ctp
bsd c cross-platform linux multi-threaded multi-threading multithreading pool thread thread-pool threading threadpool threads win32 windows windows-10 windows-7
Last synced: 1 day ago
JSON representation
C-Thread-Pool, the universal thread pool library
- Host: GitHub
- URL: https://github.com/mp81ss/ctp
- Owner: mp81ss
- License: bsd-3-clause
- Created: 2021-04-11T14:59:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-15T10:31:11.000Z (almost 2 years ago)
- Last Synced: 2025-04-19T22:59:26.092Z (about 2 months ago)
- Topics: bsd, c, cross-platform, linux, multi-threaded, multi-threading, multithreading, pool, thread, thread-pool, threading, threadpool, threads, win32, windows, windows-10, windows-7
- Language: C
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ARCHIVED - Moved to gitlab
# ARCHIVED - Moved to gitlab
# CTP
## The universal C-Thread-Pool library*CTP* is a C library that offers a pool thread, based on _pthread_, that is the only dependency.\
While easy to use, it has some interesting features:### Features
- Cross platform: Standard C; Windows, linux, bsd; 32/64 bit
- Can spawn the best number of threads according to detected cpu
- Lazy thread activation
- Ability to pause/resume
- Automatic/custom queue size
- Can block when adding work or discard if queue is full (best effort)
- Possibility to know how many threads were effectively spawned
- Dedicated API to query status in any moment (paused/idle/working)
- Easy transition from _pthread_, the work prototype has the same signature### Installation
Just compile the .c file and add it to your linker, as object or library.
If using gcc/clang, remember to complie with _-pthread_ and link with _-lpthread_If you want to use visual studio, or other windows compiler, use package
### Configuration
While compiling ctp (The library, not the clients), you can pass these variables:
- CTP_DEFAULT_THREADS_NUM
- CTP_MULTIPLY_QUEUE_FACTOR
- CTP_MIN_QUEUE_SIZE_CTP_DEFAULT_THREADS_NUM_ is used only if you pass 0 to init, and _ctp_ fails to detect core number.\
In this case, _CTP_DEFAULT_THREADS_NUM_ threads will be used. Default is **4**.\
If you pass 0 to init in the second parameter, the queue size will be calculated according to 3 parameters:\
_threads-num_, _CTP_MULTIPLY_QUEUE_FACTOR_ and _CTP_MIN_QUEUE_SIZE_. The formula is:\
```max(threads-num * CTP_MULTIPLY_QUEUE_FACTOR, CTP_MIN_QUEUE_SIZE)```\
The default value for _CTP_MULTIPLY_QUEUE_FACTOR_ is **8**.\
The default value for _CTP_MIN_QUEUE_SIZE_ is **256**---
For API details see header file. Test file may help too