EOSP ThreadPool is a header-only templated thread pool writtent in c++17.

Overview

EOSP Threadpool

Description

EOSP ThreadPool is a header-only templated thread pool writtent in c++17. It is designed to be easy to use while being able to execute any type of function. You only need two functions to use the thread pool. addTask()to add a function to execute and waitForTask() to wait the task is done. When threads are waiting for a result from other threads they compute new functions from the task pool until the result they need is available.

Exemple

fut2 = Tpool.addTask(f2); //add f2 in the task queue std::future fut1 = Tpool.addTask(f1, 7, 31); //add f1 in the task queue int result = Tpool.waitForTask(fut1); //wait the result of f1 and store the return value Tpool.waitForTask(fut2); //wait the end of the execution of f2 (void function) cout << result << endl; } ">

#include 
    
     
#include 
     
      
#include "eosp/Threadpool.hpp"


using namespace std;

int f1(int x, int y)
{
    return x*(y%x);
}

void f2()
{
    cout << "Hello World !" << endl;
}

int main()
{
    ThreadPool Tpool;				//create a default thread pool

    std::future
      
        fut2 = Tpool.addTask(f2);		//add f2 in the task queue	

    std::future
       
         fut1 = Tpool.addTask(f1, 7, 31);	//add f1 in the task queue
    int result = Tpool.waitForTask(fut1);	//wait the result of f1 and store the return value

    Tpool.waitForTask(fut2);			//wait the end of the execution of f2 (void function)

    cout << result << endl;
}

       
      
     
    

Since threads start to work on new tasks to wait before they return the first task, it can create some recursion. ThreadPool can be used with parameters to chose the number of thread and the maximum recursion depth.

ThreadPool(nbrThread, depth) creates a thread pool with nbrThread thread (default value is the number of CPU threads) And depth the maximum recursion depth which defines the number of times an unfinished task can start a new one to wait (default value is 5).

addTask(fct, param) adds a function fct with param as parameter to the pool to be compute. There can be no parameter, one or more. addTask() return an std::future where T is the return type of the fctfunction.

WaitForTask(fut) waits the task is done and return its return value if there is one. It has the same return type as fct or no return type if fct is a void function.

You might also like...
An ultra-simple thread pool implementation for running void() functions in multiple worker threads
An ultra-simple thread pool implementation for running void() functions in multiple worker threads

void_thread_pool.cpp © 2021 Dr Sebastien Sikora. [email protected] Updated 06/11/2021. What is it? void_thread_pool.cpp is an ultra-simple

High Performance Linux C++ Network Programming Framework based on IO Multiplexing and Thread Pool

Kingpin is a C++ network programming framework based on TCP/IP + epoll + pthread, aims to implement a library for the high concurrent servers and clie

Work Stealing Thread Pool

wstpool Work Stealing Thread Pool, Header Only, C++ Threads Consistent with the C++ async/future programming model. Drop-in replacement for 'async' fo

MAN - Man is Thread Pool in C++17

Introduction MAN is a ThreadPool wrote in C++17. The name is chosen because, at least in France, it is said that men are not able to do several things

CTPL - Modern and efficient C++ Thread Pool Library

CTPL Modern and efficient C++ Thread Pool Library A thread pool is a programming pattern for parallel execution of jobs, http://en.wikipedia.org/wiki/

A modern thread pool implementation based on C++20
A modern thread pool implementation based on C++20

thread-pool A simple, functional thread pool implementation using pure C++20. Features Built entirely with C++20 Enqueue tasks with or without trackin

Smart queue that executes tasks in threadpool-like manner

execq execq is kind of task-based approach of processing data using threadpool idea with extended features. It supports different task sources and mai

Light, fast, threadpool for C++20

riften::Thiefpool A blazing-fast, lightweight, work-stealing thread-pool for C++20. Built on the lock-free concurrent riften::Deque. Usage #include "r

Threadpool c++17 - 采用多线程多对列,每个线程控制一个队列,替代老的多个线程公用一个队列

ThreadPool c++17 采用多线程多对列,每个线程控制一个队列,替代老的多个线程公用一个队列。 将任务拆分多个下发给每个线程,每个线程掌管 M(tasks) / N(threads)个任务 M(tasks) / N(threads)个任务 公用一个队列。减少竞争。 使用方法: 初始化线程池

Owner
null
Thread-pool - Thread pool implementation using c++11 threads

Table of Contents Introduction Build instructions Thread pool Queue Submit function Thread worker Usage example Use case#1 Use case#2 Use case#3 Futur

Mariano Trebino 655 Dec 27, 2022
Thread-pool-cpp - High performance C++11 thread pool

thread-pool-cpp It is highly scalable and fast. It is header only. No external dependencies, only standard library needed. It implements both work-ste

Andrey Kubarkov 542 Dec 17, 2022
ThreadPool - A fastest, exception-safety and pure C++17 thread pool.

Warnings Since commit 468129863ec65c0b4ede02e8581bea682351a6d2, I move ThreadPool to C++17. (To use std::apply.) In addition, the rule of passing para

Han-Kuan Chen 124 Dec 28, 2022
ThreadPool - A simple C++11 Thread Pool implementation

ThreadPool A simple C++11 Thread Pool implementation. Basic usage: // create thread pool with 4 worker threads ThreadPool pool(4); // enqueue and sto

Jakob Progsch 6.1k Jan 7, 2023
ThreadPool - Lightweight, Generic, Pure C++11 ThreadPool

ThreadPool Lightweight, Generic, Pure C++11 ThreadPool Rational I needed a Thread Pool for something I was writing, and I didn't see any that I liked.

Neil 266 Jan 8, 2023
DwThreadPool - A simple, header-only, dependency-free, C++ 11 based ThreadPool library.

dwThreadPool A simple, header-only, dependency-free, C++ 11 based ThreadPool library. Features C++ 11 Minimal Source Code Header-only No external depe

Dihara Wijetunga 27 Oct 28, 2022
Pool is C++17 memory pool template with different implementations(algorithms)

Object Pool Description Pool is C++17 object(memory) pool template with different implementations(algorithms) The classic object pool pattern is a sof

KoynovStas 1 Nov 18, 2022
A easy to use multithreading thread pool library for C. It is a handy stream like job scheduler with an automatic garbage collector. This is a multithreaded job scheduler for non I/O bound computation.

A easy to use multithreading thread pool library for C. It is a handy stream-like job scheduler with an automatic garbage collector for non I/O bound computation.

Hyoung Min Suh 12 Jun 4, 2022
A C++17 thread pool for high-performance scientific computing.

We present a modern C++17-compatible thread pool implementation, built from scratch with high-performance scientific computing in mind. The thread pool is implemented as a single lightweight and self-contained class, and does not have any dependencies other than the C++17 standard library, thus allowing a great degree of portability

Barak Shoshany 1.1k Jan 4, 2023
An easy to use C++ Thread Pool

mvThreadPool (This library is available under a free and permissive license) mvThreadPool is a simple to use header only C++ threadpool based on work

Jonathan Hoffstadt 30 Dec 8, 2022