38 std::vector<std::thread> _threads;
40 ::std::atomic<bool> _is_shutdown;
41 static thread_local int _worker_id;
66 ThreadPool &
operator=(
const ThreadPool &other) =
delete;
78 if (_is_shutdown.load(::std::memory_order_acquire))
79 throw ::std::runtime_error(
"Thread pool submit error - Submit cannot be called after thread pool is shut down");
81 auto p = std::make_shared< std::promise<T> >();
82 std::future<T> fut = p->get_future();
85 if constexpr (std::is_void_v<T>) {
89 p->set_value(f(
arena));
ThreadPool(ThreadPool &&other)=delete
static int get_worker_id()
Get the thread-local id of a worker.
void shutdown()
Shut the ThreadPool down.
ThreadPool & operator=(const ThreadPool &other)=delete
ThreadPool(const ThreadPool &other)=delete
static ThreadPool * get_thread_pool(ThreadPoolConfig config={ default_arena_init_block_ct })
Get the instance of the ThreadPool singleton.
ThreadPool & operator=(ThreadPool &&other)=delete
std::future< T > submit(std::function< T(arena_t *arena) > f)
Submit a task to the ThreadPool.
Definition ThreadPool.h:77
Structures and algorithms used for multithreaded operations.
std::function< void(arena_t *) > Func
Definition ThreadPool.h:20
constexpr size_t default_arena_init_block_ct
The default amount of blocks allocated to a newly initialized arena.
Definition ThreadPool.h:23
The configuration of the ThreadPool.
Definition ThreadPool.h:26
size_t arena_blocks_to_allocate
Definition ThreadPool.h:27
A thread local mini "heap" used for thread local memory allocation.
Definition Arena.h:36