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);gcc -std=gnu99 -o main test.c worker_pool.c -lpthread
./mainoutput:
start worker 1
start worker 2
end worker 2
start worker 1
start worker 2
end worker 2
start worker 1
start worker 2some action use pthread_barrier_* functions to sync data without lock.
- use lock free struct to release lock time wait.
- destroy with wait.
- execute more fast.