// // Created by Christopher Hamer on 19/06/2024. // #ifndef TASK1_THREADPOOL_H #define TASK1_THREADPOOL_H #include #include #include #include #include #include using namespace std; // Class that represents a simple thread pool class ThreadPool { public: // // Constructor to creates a thread pool with given // number of threads ThreadPool(size_t num_threads); // Destructor to stop the thread pool ~ThreadPool(); // Enqueue task for execution by the thread pool void enqueue(function task); private: // Vector to store worker threads vector threads_; // Queue of tasks queue > tasks_; // Mutex to synchronize access to shared data mutex queue_mutex_; // Condition variable to signal changes in the state of // the tasks queue condition_variable cv_; // Flag to indicate whether the thread pool should stop // or not bool stop_ = false; }; #endif //TASK1_THREADPOOL_H