4#ifndef NO_MULTITHREADING
8#include <condition_variable>
21 ThreadPool(
size_t num_threads);
22 ThreadPool(
const ThreadPool& other) =
delete;
23 ThreadPool(ThreadPool&& other) =
delete;
26 ThreadPool& operator=(
const ThreadPool& other) =
delete;
27 ThreadPool& operator=(ThreadPool&& other) =
delete;
29 void start_tasks(
size_t num_iterations,
const std::function<
void(
size_t)>& func)
35 num_iterations_ = num_iterations;
39 condition.notify_all();
46 complete_condition_.wait(lock, [
this] {
return complete_ == num_iterations_; });
52 std::vector<std::thread> workers;
53 std::mutex tasks_mutex;
54 std::function<void(
size_t)> task_;
55 size_t num_iterations_ = 0;
56 size_t iteration_ = 0;
70 if (iteration_ == num_iterations_) {
73 iteration = iteration_++;
79 if (++complete_ == num_iterations_) {
80 complete_condition_.notify_one();
88ThreadPool::ThreadPool(
size_t num_threads)
90 workers.reserve(num_threads);
91 for (
size_t i = 0; i < num_threads; ++i) {
92 workers.emplace_back(&ThreadPool::worker_loop,
this, i);
96ThreadPool::~ThreadPool()
102 condition.notify_all();
103 for (
auto& worker : workers) {
108void ThreadPool::worker_loop(
size_t )
114 condition.wait(lock, [
this] {
return (iteration_ < num_iterations_) || stop; });
141 bool expected =
false;
142 if (!nested.compare_exchange_strong(expected,
true)) {
144 for (
size_t i = 0; i < num_iterations; ++i) {
150 pool.start_tasks(num_iterations, func);
Entry point for Barretenberg command-line interface.
void parallel_for_mutex_pool(size_t num_iterations, const std::function< void(size_t)> &func)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static thread_local TimeStatsEntry * parent