项目作者: senlinzhan

项目描述 :
使用 C++11 实现的动态线程池
高级语言: C++
项目地址: git://github.com/senlinzhan/dpool.git


License: MIT Build status

dpool

使用 C++11 实现的动态线程池,主要特性:

  • 使用简单,不易出错。
  • 支持线程复用,提升性能。
  • 支持懒惰创建线程。
  • 必要时自动回收空闲的线程。

快速上手

  1. #include "ThreadPool.hpp"
  2. #include <iostream>
  3. int compute(int a, int b)
  4. {
  5. return a + b;
  6. }
  7. int main()
  8. {
  9. // 设置最大线程数为 10
  10. dpool::ThreadPool pool(10);
  11. auto fut = pool.submit(compute, 100, 100);
  12. std::cout << "100 + 100 = " << fut.get() << std::endl;
  13. return 0;
  14. }