Skip to content

silkcutKs/c_thread_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

worker_pool *wp =  create_worker_pool(worker_num);

second, add task which you want to execute async.

add_task(wp, execute_func, data);  

finally, destroy your worker_pool.

destroy_worker_pool(wp);

extra, monitor run status.

dump_worker_pool_status(worker_pool *wp);

test

gcc -std=gnu99 -o main test.c worker_pool.c -lpthread
./main

output:

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.

Releases

No releases published

Packages

No packages published

Languages