1#ifndef NO_MULTITHREADING
5#include <condition_variable>
16 ThreadPool(
size_t num_threads);
17 ThreadPool(
const ThreadPool& other) =
delete;
18 ThreadPool(ThreadPool&& other) =
delete;
21 ThreadPool& operator=(
const ThreadPool& other) =
delete;
22 ThreadPool& operator=(ThreadPool&& other) =
delete;
24 void start_tasks(
size_t num_iterations,
const std::function<
void(
size_t)>& func)
29 num_iterations_ = num_iterations;
31 iterations_completed_ = 0;
33 condition.notify_all();
37 while (iterations_completed_ != num_iterations) {
42 std::vector<std::thread> workers;
43 std::mutex tasks_mutex;
44 std::function<void(
size_t)> task_;
45 size_t num_iterations_ = 0;
46 std::atomic<size_t> iteration_;
47 std::atomic<size_t> iterations_completed_;
51 void worker_loop(
size_t thread_index);
59 iterations_completed_++;
64ThreadPool::ThreadPool(
size_t num_threads)
66 , iterations_completed_(0)
68 workers.reserve(num_threads);
69 for (
size_t i = 0; i < num_threads; ++i) {
70 workers.emplace_back(&ThreadPool::worker_loop,
this, i);
74ThreadPool::~ThreadPool()
80 condition.notify_all();
81 for (
auto& worker : workers) {
86void ThreadPool::worker_loop(
size_t )
92 condition.wait(lock, [
this] {
return (iteration_ < num_iterations_) || stop; });
114 pool.start_tasks(num_iterations, func);
Entry point for Barretenberg command-line interface.
void parallel_for_atomic_pool(size_t num_iterations, const std::function< void(size_t)> &func)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept