Skip to content

About

C++20 Thread Pool

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

C++20 Thread Pool (header file only)

MIT license cmake Build clang Build profile Build cppcheck Build Coverage Status

About

This is a header file only implementation of a C++20 style thread pool.

Compilation has been tested with:

  • GCC 11.3.0 (GNU/Linux Ubuntu 22.04.1 LTS)
    • cmake 3.22.1
    • googletest 1.11.0-3
    • clang 14.0.0-1ubuntu1
  • Visual Studio Community 2022 17.4.4 (64-bit) (Windows 11)
    • cmake 3.26.0-rc1
    • googletest 1.13.0

Usage

Create a thread pool and add jobs to it to be performed by the running threads.

void printVal(void)
{
    static int val = 1;
    std::cout << "Thread job: " << val++ << std::endl;
}

auto main(int argc, char* argv[]) -> int 
{
    com::thread::Pool p(1);

    for (auto i = 0; i < 5; ++i)
    {
        p.add(printVal);
    }
    ...
}

Thread Safety

All methods of the thread pool are thread safe.

Installation

Use the ThreadPool.hpp file in your source tree and include it in the file that need to use it.

Run Unit Tests

Unit tests run with ctest:

ctest -VV -C debug

Contribute

All contributions are highly appreciated.

About

C++20 Thread Pool

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages