https://github.com/silkcutks/c_thread_pool
thread pool with c language
https://github.com/silkcutks/c_thread_pool
c pthreads threadpool workpool
Last synced: 8 months ago
JSON representation
thread pool with c language
- Host: GitHub
- URL: https://github.com/silkcutks/c_thread_pool
- Owner: silkcutKs
- Created: 2017-12-06T08:22:22.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-06T09:08:15.000Z (about 8 years ago)
- Last Synced: 2023-08-08T14:41:45.764Z (over 2 years ago)
- Topics: c, pthreads, threadpool, workpool
- Language: C
- Size: 2.93 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# c language thread pool
## use
build your executable file with `worker_pool.c -lpthread`
first step, create worker pool with worker num, which will effect your concurrence.
```c
worker_pool *wp = create_worker_pool(worker_num);
```
second, add task which you want to execute async.
```c
add_task(wp, execute_func, data);
```
finally, destroy your worker_pool.
```c
destroy_worker_pool(wp);
```
extra, monitor run status.
```c
dump_worker_pool_status(worker_pool *wp);
```
## test
```shell
gcc -std=gnu99 -o main test.c worker_pool.c -lpthread
./main
```
output:
```shell
start worker 1
start worker 2
end worker 2
start worker 1
start worker 2
end worker 2
start worker 1
start worker 2
```
## advantage
some action use `pthread_barrier_*` functions to sync data without lock.
## next
- use lock free struct to release lock time wait.
- destroy with wait.
- execute more fast.