Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

threadPool

固定线程池,基于 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 — 演示程序

API

#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

About

C的线程池库,依赖链表

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages