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_++;
89 if (++complete_ == num_iterations_) {
90 complete_condition_.notify_one();
98ThreadPool::ThreadPool(
size_t num_threads)
100 workers.reserve(num_threads);
101 for (
size_t i = 0; i < num_threads; ++i) {
102 workers.emplace_back(&ThreadPool::worker_loop,
this, i);
106ThreadPool::~ThreadPool()
112 condition.notify_all();
113 for (
auto& worker : workers) {
118void ThreadPool::worker_loop([[maybe_unused]]
size_t thread_index)
124 condition.wait(lock, [
this] {
return (iteration_ < num_iterations_) || stop; });
147#define THREAD_LOCAL_MAYBE
149#define THREAD_LOCAL_MAYBE thread_local
157 for (
size_t i = 0; i < num_iterations; ++i) {
164 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