HiPipe  0.7.0
C++17 data pipeline with Python bindings.
Public Member Functions | List of all members
hipipe::thread_pool Class Reference

A simple thread pool class. More...

#include <hipipe/core/thread.hpp>

Public Member Functions

 thread_pool (unsigned n_threads=std::thread::hardware_concurrency())
template<typename Fun , typename... Args>
std::future< std::result_of_t< Fun(Args...)> > enqueue (Fun fun, Args... args)
 ~thread_pool ()

Detailed Description

A simple thread pool class.

This class manages the given number of threads across which it automatically distributes the given tasks.

Definition at line 30 of file thread.hpp.

Constructor & Destructor Documentation

◆ thread_pool()

hipipe::thread_pool::thread_pool ( unsigned  n_threads = std::thread::hardware_concurrency())

Spawn the given number of threads and start processing the queue.

n_threadsThe number of threads to be spawned.

Definition at line 41 of file thread.hpp.

◆ ~thread_pool()

hipipe::thread_pool::~thread_pool ( )

Thread pool destructor.

The destructor blocks until all the enqueued tasks are finished.

Definition at line 86 of file thread.hpp.

Member Function Documentation

◆ enqueue()

template<typename Fun , typename... Args>
std::future<std::result_of_t<Fun(Args...)> > hipipe::thread_pool::enqueue ( Fun  fun,
Args...  args 

Enqueue a function for processing.

auto fun = [](int i) { return i + 1; };
std::future<int> f1 = tp.enqueue(fun, 10);
std::future<int> f2 = tp.enqueue(fun, 11);
assert(f1.get() == 11);
assert(f2.get() == 12);
funThe function to be executed.
argsParameters for the function. Note that they are taken by value.
An std::future corresponding to the result of the function call.

Definition at line 66 of file thread.hpp.

The documentation for this class was generated from the following file:
thread_pool(unsigned n_threads=std::thread::hardware_concurrency())
Definition: thread.hpp:41