Code Monkey home page Code Monkey logo

cthreadpool's Introduction

languages os stars forks

CThreadPool 说明文档

一. 简介

CThreadPool 是一个跨平台的、无任何三方依赖的、高性能的C++11(含以上版本)版本的线程池,也是 CGraph 项目中使用的跨平台线程池组件功能的最小集。

经过CGraph和关联项目的长期迭代和验证,功能已经趋于稳定,且性能优异。因为咨询相关内容的朋友较多,故做为独立的仓库提供出来,方便大家使用。

由于是CGraph项目中的剥离出来的功能类,故在项目中保留了多处 CGRAPH_* 的命名方式,仅将 namespace 修改为 CTP,预计今后与CGraph相互独立更新。

本项目参考了《C++并发编程实战(第二版)》 中的部分内容,和github上的一些优秀实现。并在此基础上进行大量的改动、扩展和优化,在功能、性能和易用性上均有较大的提升。

在开发过程中,也沉淀了详细的说明文档(见下方 推荐阅读),以便于大家快速了解代码和思路,也请大家不吝指教。

二. 编译说明

  • 本工程支持MacOS、Linux和Windows系统,无任何第三方依赖。推荐使用C++11(默认)或以上版本,不支持以下C++11以下版本

  • 使用CLion或使用Visual Studio 15(或以上版本)作为IDE的开发者,打开CMakeLists.txt文件作为工程,即可编译通过

  • Linux环境开发者,在命令行模式下,输入以下指令,即可编译通过

$ git clone https://github.com/ChunelFeng/CThreadPool.git
$ cd CThreadPool
$ cmake . -Bbuild
$ cd build
$ make -j8

三. 使用Demo

#include "src/CThreadPool.h"

using namespace CTP;

float add_by_5(float i) {
    return i + 5.0f;
}

int main() {
    UThreadPool tp;
    int i = 6, j = 3;
    auto r1 = tp.commit([i, j] { return i - j; });
    std::future<float> r2 = tp.commit(std::bind(add_by_5, 8.5f));

    std::cout << r1.get() << std::endl;
    std::cout << r2.get() << std::endl;
    return 0;
}

更多使用方法,请参考 tutorial.cpp 中的例子和文档中的内容。

四. 推荐阅读

五. 关联项目


附录-1. 版本信息

[2022.10.05 - v1.0.0 - Chunel]

  • 提供线程池基本功能
  • 提供对应的tutorial信息

[2022.10.07 - v1.0.1 - Chunel]

  • 提供默认开启辅助线程的配置

[2022.10.11 - v1.1.0 - MirrorYuChen]

  • 提供针对C++11版本的支持

附录-2. 联系方式

CGraph Author

cthreadpool's People

Contributors

chunelfeng avatar mirroryuchen 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.