Coder Social home page Coder Social logo

thread-pool's Introduction

C++ thread pool library

Description

C++ thread pool library implementation.

Cloning repository

git clone --recursive https://github.com/rsitko92/thread-pool.git

Prerequisites

Prerequisites for running thread pool unit tests

Prerequisites for using thread pool in project with CMake

Running unit tests

Running unit tests with using Docker

Being in root directory of project run in terminal:

sudo test/buildAndRunTestsDocker.sh

Running unit tests without using Docker

Being in root directory of project run in terminal:

test/buildAndRunTests.sh

Using thread pool library in project with CMake

  1. Add thread pool project using ExternalProject_Add function in CMakeLists.txt file.

  2. Link libThreadPool.a static library to project target in CMakeLists.txt file.

  3. Include DefaultFixedThreadPool.hpp header file from inc directory in header/source file:

    #include "DefaultFixedThreadPool.hpp"
  4. Create thread pool instance:

    auto pThreadPool = thread_pool::DefaultFixedThreadPool::create();
  5. Enqueue task in thread pool:

    auto exampleTask = [](int x)
      {std::this_thread::sleep_for(std::chrono::seconds(2));
      std::cout << "Hello from worker thread" << std::endl;
      std::cout << "Passed argument value = " << x << std::endl;};
    auto future = pThreadPool->enqueue(exampleTask, 10);

    Notice 1: In this example also chrono and iostream headers must be included.

    Notice 2: You can enqueue tasks and its arguments as rvalue objects. Then there will be invoked move constructors if exists for these class of objects.

  6. Get result:

    future.get();

thread-pool's People

Contributors

r-sitko avatar

Stargazers

 avatar

Watchers

 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.