Kaspersky Neuromorphic Platform  1.0.0
API Reference
Loading...
Searching...
No Matches
thread_pool.h
Go to the documentation of this file.
1
21#pragma once
22#include <memory>
23
24#include "thread_pool_context.h"
26
27
32{
37{
38public:
43 explicit ThreadPool(size_t num_threads)
44 : context_(std::make_unique<ThreadPoolContext>(num_threads)), executor_(*context_)
45 {
46 }
47
56 template <class Func, typename... Args>
57 void post(Func func, Args... args)
58 {
59 boost::asio::post(executor_, std::bind(func, args...));
60 }
61
66 void join() { executor_.join(); }
67
68private:
69 // Do not change the order of declarations.
70 std::unique_ptr<ThreadPoolContext> context_;
71 ThreadPoolExecutor executor_;
72};
73
74} // namespace knp::backends::cpu_executors
The ThreadPool class is a definition of thread pool.
Definition thread_pool.h:37
ThreadPool(size_t num_threads)
Create thread pool.
Definition thread_pool.h:43
void post(Func func, Args... args)
Add task to pool.
Definition thread_pool.h:57
void join()
Wait until all threads stop processing.
Definition thread_pool.h:66
Namespace for CPU backend executors.
Definition backend.h:50
Context for reusable thread pool class, a modified example from asio documentation.
Thread pool executor class.