GithubHelp home page GithubHelp logo

light-thread-pool's Introduction

基于Arrow的轻量线程池

这个项目的线程池是基于Apache Arrow项目的衍生版本。我们将Arrow项目中复杂的核心结构——线程池——完全剥离出来,形成了这个独立的项目。由于原始的线程池与Arrow项目本身的工具有深度依赖关系,因此我们在这个项目中对线程池进行了一些深度移除和改造,以保持与原始Arrow线程池的基础功能一致。一些改动包括:

  • 将Arrow的Future替换为std::future
  • 将Arrow的Result替换为std::optional
  • 重构了Submit接口,使用promise进行实现

通过这些改动,我们的目标是:

  • 使线程池更方便地作为其他项目的依赖库使用
  • 提供简单的方式来引入本项目的so库和头文件,以使用线程池功能

此外,这个项目还可以作为深入学习线程池设计与实现的资源。我们欢迎您探索并使用这个经过精心改进的线程池。

1.如何编译

➜ bazel build //src:thread_pool
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
INFO: Analyzed target //src:thread_pool (36 packages loaded, 168 targets configured).
INFO: Found 1 target...
Target //src:thread_pool up-to-date:
  bazel-bin/src/libthread_pool.a
  bazel-bin/src/libthread_pool.dylib
INFO: Elapsed time: 1.748s, Critical Path: 1.34s
INFO: 8 processes: 3 internal, 5 darwin-sandbox.
INFO: Build completed successfully, 8 total actions

2.如何使用

所有的用例放在examples目录

2.1 编写一个简单的case

参见:helloworld

// Create a thread pool
auto threadPool = GetCpuThreadPool();
if (!threadPool) {
  std::cerr << "Failed to create thread pool" << std::endl;
  return 1;
}

// Submit tasks to the thread pool
threadPool->Spawn([]() { std::cout << "hello world!" << std::endl; });

// Wait for all tasks to complete
threadPool->WaitForIdle();

// Shutdown the thread pool
threadPool->Shutdown();

其他case:

  • 设置线程池数量
  • 如何停止回调
  • 如何异步处理

3.如何测试

测试基于catch2编写,所有测试位于tests目录

可以测试tests目录下面的其他测试,只需要替换submit_test为对应的test即可。

bazel test //tests:submit_test

light-thread-pool's People

Contributors

light-city 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.