Skip to content

andrmr/cpp_thread_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp_thread_pool

Thread pool written in C++ 17

Runs queued tasks on a given number of reusable threads.

Usage:

#include "ThreadPool.h"

#include <iostream>

auto free_func(int a, int b, int c) {
    return a + b + c;
}

auto lambda_func = [](auto&&... args) -> typename std::common_type<decltype(args)...>::type {
    return (args + ...);
};

struct Pod {
    auto mem_func(int a, int b, int c) {
        return a + b + c;
    }
};

int main() {
    TP::ThreadPool tp(std::thread::hardware_concurrency());

    // queue free function
    auto f = tp.addTask(free_func, 1, 2, 3);

    // queue variadic lambda or template wrapper
    auto g = tp.addTask(lambda_func, 1, 2, 3.5);

    // queue member function
    auto h = tp.addTask(std::mem_fn(&Pod::mem_func), Pod {}, 1, 2, 3);

    std::cout << f.get() << '\n' << g.get() << '\n' << h.get() << '\n';

    tp.stop();
    return 0;
}

TODO:

  • create more tests or move to a UT framework
  • improve flexibility i.e. overloads, dynamic resizing

About

Thread pool written in C++ 17 (with 14 branch).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published