Skip to content

heig-tin-info/example-cpp-thread-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thread Pool

A simple implementation of a thread pool in C++.

Other implementations

BS Thread Pool

BS Thread Pool is a header-only C++11 thread pool implementation. It provides a simple and efficient way to manage a pool of worker threads and execute tasks asynchronously.

wget https://raw.githubusercontent.com/bshoshany/thread-pool/master/include/BS_thread_pool.hpp

Boost Thread Pool

Boost Thread Pool is a part of the Boost C++ Libraries that provides a thread pool implementation. It allows you to manage a pool of worker threads and execute tasks asynchronously.

sudo apt-get install libboost-all-dev
#include <boost/asio/thread_pool.hpp>
#include <boost/asio/post.hpp>
#include <iostream>
#include <chrono>

int main()
{
    boost::asio::thread_pool pool(4);

    for (int i = 0; i < 10; ++i) {
        boost::asio::post(pool, [i] {
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
            std::cout << "Task " << i << " completed\n";
        });
    }

    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    std::cout << "Shutting down thread pool...\n";
    pool.join();
}

About

Simple implementation of a thread pool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages