zserik/ThreadPool


A simple C++ Thread Pool implementation - fork of https://github.com/progschj/ThreadPool

License: Zlib

Language: C++


ThreadPool pipeline status

A simple C++17 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;

Simple example program:

#include <iostream>
#include <vector>
#include <chrono>

#include "ThreadPool.h"

int main()
{
    ThreadPool pool(4);
    std::vector< std::future<int> > results;

    for(int i = 0; i < 8; ++i) {
        results.emplace_back(
            pool.enqueue([i] {
                std::cout << "hello " << i << std::endl;
                std::this_thread::sleep_for(std::chrono::seconds(1));
                std::cout << "world " << i << std::endl;
                return i*i;
            })
        );
    }

    for(auto && result: results)
        std::cout << result.get() << ' ';
    std::cout << std::endl;

    return 0;
}

Project Statistics

Sourcerank 4
Repository Size 34.2 KB
Stars 5
Forks 1
Watchers 2
Open issues 1
Dependencies 0
Contributors 9
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

Jakob Progsch Jan Niklas Hasse Youka zserik Václav Haisman FreddyFunk Tamás Szelei VZ danilcha

Something wrong with this page? Make a suggestion

Last synced: 2019-11-04 01:52:43 UTC

Login to resync this repository