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
"
25
#include "
thread_pool_executor.h
"
26
27
31
namespace
knp::backends::cpu_executors
32
{
36
class
ThreadPool
37
{
38
public
:
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
68
private
:
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
knp::backends::cpu_executors::ThreadPool
The ThreadPool class is a definition of thread pool.
Definition
thread_pool.h:37
knp::backends::cpu_executors::ThreadPool::ThreadPool
ThreadPool(size_t num_threads)
Create thread pool.
Definition
thread_pool.h:43
knp::backends::cpu_executors::ThreadPool::post
void post(Func func, Args... args)
Add task to pool.
Definition
thread_pool.h:57
knp::backends::cpu_executors::ThreadPool::join
void join()
Wait until all threads stop processing.
Definition
thread_pool.h:66
knp::backends::cpu_executors
Namespace for CPU backend executors.
Definition
backend.h:50
thread_pool_context.h
Context for reusable thread pool class, a modified example from asio documentation.
thread_pool_executor.h
Thread pool executor class.