R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ThreadPool.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** Created by hugo on 06/12/2025
4** File description:
5** ThreadPool.hpp
6*/
7
8#pragma once
9
10#include <thread>
13
14namespace server {
15
23 class ThreadPool : public IThreadPool {
24 public:
25 explicit ThreadPool(size_t threadCount);
26 ~ThreadPool() override;
27
28 void enqueue(Task task) override;
29 void start() override;
30 void stop() override;
31 size_t size() const override;
32
33 private:
40 void _workerLoop(std::stop_token stopToken);
41
43 std::vector<std::jthread> _workers;
45 };
46
47} // namespace server
Thread-safe queue for inter-thread communication.
Interface for a thread pool.
std::function< void()> Task
Concrete implementation of IThreadPool.
size_t size() const override
Get the number of threads in the pool.
~ThreadPool() override
std::vector< std::jthread > _workers
void stop() override
Stop all threads and clean up resources.
void _workerLoop(std::stop_token stopToken)
Worker thread main loop Continuously pulls tasks from the queue and executes them.
void enqueue(Task task) override
Enqueue a task to be executed by the thread pool.
void start() override
Start all threads in the pool.
ThreadSafeQueue< Task > _taskQueue