4#ifndef NO_MULTITHREADING
8#include <condition_variable>
25alignas(16)
thread_local char tls_alignment_pad[16]
__attribute__((used)) = { 1 };
32 ThreadPool(
size_t num_threads);
33 ThreadPool(
const ThreadPool& other) =
delete;
34 ThreadPool(ThreadPool&& other) =
delete;
37 ThreadPool& operator=(
const ThreadPool& other) =
delete;
38 ThreadPool& operator=(ThreadPool&& other) =
delete;
40 void start_tasks(
size_t num_iterations,
const std::function<
void(
size_t)>& func)
46 num_iterations_ = num_iterations;
50 condition.notify_all();
57 complete_condition_.wait(lock, [
this] {
return complete_ == num_iterations_; });
63 std::vector<std::thread> workers;
64 std::mutex tasks_mutex;
65 std::function<void(
size_t)> task_;
66 size_t num_iterations_ = 0;
67 size_t iteration_ = 0;
81 if (iteration_ == num_iterations_) {
84 iteration = iteration_++;
90 if (++complete_ == num_iterations_) {
91 complete_condition_.notify_one();
99ThreadPool::ThreadPool(
size_t num_threads)
101 workers.reserve(num_threads);
102 for (
size_t i = 0; i < num_threads; ++i) {
103 workers.emplace_back(&ThreadPool::worker_loop,
this, i);
107ThreadPool::~ThreadPool()
113 condition.notify_all();
114 for (
auto& worker : workers) {
119void ThreadPool::worker_loop(
size_t )
125 condition.wait(lock, [
this] {
return (iteration_ < num_iterations_) || stop; });
148#define THREAD_LOCAL_MAYBE
150#define THREAD_LOCAL_MAYBE thread_local
158 for (
size_t i = 0; i < num_iterations; ++i) {
165 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
thread_local char tls_alignment_pad[16] __attribute__((used))
#define THREAD_LOCAL_MAYBE
static thread_local TimeStatsEntry * parent