固定线程池,基于 linkedList + pthread。适用于 MQTT 消息处理等生产者-消费者场景。
- linkedList — 任务队列
- pthread — 线程同步(POSIX,系统自带)
# 先构建 linkedList
git clone https://github.com/MaxBellc/linkedList
cd linkedList && mkdir build && cd build
cmake .. && make -j$(nproc)
# 再构建 threadPool
cd /path/to/threadPool && mkdir build && cd build
cmake .. -DLINKEDLIST_ROOT=/path/to/linkedList
make -j$(nproc)产物:
libthreadpool.a— 静态库test_thread_pool— 单元测试pool_demo— 演示程序
#include "thread_pool.h"
THREAD_POOL *pool = thread_pool_create(4); // 4 个工作线程
thread_pool_submit(pool, my_handler, my_arg); // 提交任务
thread_pool_wait(pool); // 等待完成
thread_pool_destroy(pool); // 销毁./build/test_thread_pool
# 7 项测试,全部通过MIT