Skip to content

lmartinpierrat/Cpp-ThreadPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

MIT licensed

This is a simple generic threadpool in c++.

Example

#include    "ThreadPool.hpp"

#include    <iostream>

std::ostream &operator<<(std::ostream &os, const std::vector<std::thread::id> &thread_ids)
{
    for (const auto &thread_id : thread_ids)
    {
        os << "[" << thread_id << "]";
    }
    os << std::endl;
    return os;
}

int     main(void)
{
    ThreadPool  threadpool(std::thread::hardware_concurrency());
    std::vector<std::thread::id>    thread_ids(1000, std::this_thread::get_id());

    for (std::size_t job_number = 0; job_number < 1000; ++job_number)
    {
        threadpool.add([=, &thread_ids]() {
            thread_ids[job_number] = std::this_thread::get_id();
        });
    }
    threadpool.wait_unfinished_jobs();
    std::cout << thread_ids << std::endl;
}

possible output :

[4636][5848][5848][5848][4636][5848][4636][3224][4636] ... [5848][5796][3224][5848][5796][3224][5848][5796][3224][5848][5796][3224]

About

light threadpool using modern c++.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages