Skip to content

A simple C++11 Thread Pool implementation. 一个C++11线程池实现 (中文注释版)。

License

Notifications You must be signed in to change notification settings

Camio1945/ThreadPool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

改动说明

  1. 在 ThreadPool.h 和 example.cpp 中增加了中文注释。
  2. 把少数一些嵌套的变量提取出来了,方便调试。如:

auto task = std::make_shared< std::packaged_task<return_type()> >(
        std::bind(std::forward<F>(f), std::forward<Args>(args)...)
    );

改成了

auto callableBind = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
auto task = std::make_shared< std::packaged_task<return_type()> >(callableBind);
  1. 通过clang-format格式化了代码。
  2. 给条件判断后的单行语句增加了括号。如:

for (auto &&result: results)
  std::cout << result.get() << ' ';

改成了

for (auto &&result: results) {
  std::cout << result.get() << ' ';
}
  1. example.cpp 中增加耗时统计。

ThreadPool

A simple C++11 Thread Pool implementation.

Basic usage:

// create thread pool with 4 worker threads
ThreadPool pool(4);

// enqueue and store future
auto result = pool.enqueue([](int answer) { return answer; }, 42);

// get result from future
std::cout << result.get() << std::endl;

About

A simple C++11 Thread Pool implementation. 一个C++11线程池实现 (中文注释版)。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.9%
  • CMake 2.1%