GithubHelp home page GithubHelp logo

yuy4o / threadpool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from camio1945/threadpool

0.0 0.0 0.0 17 KB

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

License: zlib License

C++ 97.89% CMake 2.11%

threadpool's Introduction

改动说明

  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;

threadpool's People

Contributors

progschj avatar wilx avatar vadz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.