Giter Club home page Giter Club logo

threadpool's Introduction

Sean's Thread Pool

This is a single-file, header only implementation of a thread pool using C++17 features. It was created for my own edification and intended only for my own use, but I hope someone else may find it useful or the implementation instructive. It has no dependencies beyond a C++17-compliant compiler and the standard library.

The interface is simple:

using namespace ThreadPool;

// Create a thread pool:
ThreadPool thread_pool(num_threads);

// Any callable can be submitted to the thread pool very simply;
// define some function we want to submit:
auto f = [](int x, int y) { return x + y; };

// Call ThreadPool::submit(f, args...) to submit the task; this function
// returns std::future<std::invoke_result_t<f, args...>>
std::future<int> future = thread_pool.submit(f, 2, 3);

For a less trivial example, see 'calc_pi.cpp' which implements a Monte Carlo algorithm to calculate pi using the thread pool.

Acknowledgement

This article by Will Pearce was invaluable in developing the understanding needed of synchronization primitives and the considerations necessary to get a thread pool working.

License

Copyright (c) Sean McBane 2018 under the terms of the MIT License; see LICENSE.txt for the details.

threadpool's People

Stargazers

Hyeongbin Kim avatar

Watchers

Sean McBane avatar

Forkers

prasantapal

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.