Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
thread_pool.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifndef NO_MULTITHREADING
4
5#include <atomic>
6#include <condition_variable>
7#include <functional>
8#include <mutex>
9#include <queue>
10#include <thread>
11#include <vector>
12namespace bb {
14 public:
15 ThreadPool(size_t num_threads);
16 ThreadPool(const ThreadPool& other) = delete;
17 ThreadPool(ThreadPool&& other) = delete;
19
20 ThreadPool& operator=(const ThreadPool& other) = delete;
21 ThreadPool& operator=(ThreadPool&& other) = delete;
22
23 void enqueue(const std::function<void()>& task);
24 void wait();
25 size_t num_threads() { return workers.size(); };
26
27 private:
28 std::vector<std::thread> workers;
29 std::queue<std::function<void()>> tasks;
30 std::mutex tasks_mutex;
33 std::atomic<size_t> tasks_running;
34 bool stop = false;
35
36 void worker_loop(size_t thread_index);
37};
38} // namespace bb
39
40#endif
ThreadPool & operator=(ThreadPool &&other)=delete
std::mutex tasks_mutex
std::condition_variable finished_condition
std::vector< std::thread > workers
size_t num_threads()
ThreadPool(ThreadPool &&other)=delete
std::atomic< size_t > tasks_running
std::condition_variable condition
void worker_loop(size_t thread_index)
void enqueue(const std::function< void()> &task)
ThreadPool(const ThreadPool &other)=delete
std::queue< std::function< void()> > tasks
ThreadPool & operator=(const ThreadPool &other)=delete
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13