From 6e51e5cbe609a849d6731b61df45d8ba71f8deed Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Sat, 30 Dec 2023 17:05:57 -0500 Subject: [PATCH] add features --- include/blt/std/thread.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/blt/std/thread.h b/include/blt/std/thread.h index feddaf5..38555f6 100644 --- a/include/blt/std/thread.h +++ b/include/blt/std/thread.h @@ -40,13 +40,16 @@ namespace blt private: typedef std::function thread_function; volatile std::atomic_bool should_stop = false; + volatile std::atomic_uint64_t stopped = 0; + std::uint64_t number_of_threads = 0; std::vector threads; std::variant, thread_function> func_queue; std::mutex queue_mutex; public: - explicit thread_pool(size_t number_of_threads = 8) + explicit thread_pool(std::uint64_t number_of_threads = 8) { - for (size_t i = 0; i < number_of_threads; i++) + this->number_of_threads = number_of_threads; + for (std::uint64_t i = 0; i < number_of_threads; i++) { threads.push_back(new std::thread([this]() { while (!should_stop) @@ -81,6 +84,7 @@ namespace blt func(); } } + stopped++; })); } } @@ -98,6 +102,10 @@ namespace blt } } + [[nodiscard]] inline bool complete() const { + return stopped == number_of_threads; + } + inline void stop() { should_stop = true;