diff --git a/src/EC/ThreadPool.hpp b/src/EC/ThreadPool.hpp index 50b7af7..bdb2d93 100644 --- a/src/EC/ThreadPool.hpp +++ b/src/EC/ThreadPool.hpp @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -23,8 +23,8 @@ namespace Internal { using TPFnType = std::function; using TPTupleType = std::tuple; using TPQueueType = std::queue; -using ThreadPtr = std::unique_ptr; -using ThreadStackType = std::vector>; +using ThreadOpt = std::optional; +using ThreadStackType = std::vector>; using ThreadStacksType = std::deque; using ThreadStacksMutexesT = std::deque; using ThreadCountersT = std::deque; @@ -82,7 +82,7 @@ class ThreadPool { std::mutex *threadStackMutex = std::get<1>(pointers); std::atomic_uint *aCounter = std::get<2>(pointers); for (unsigned int i = 0; i < MAXSIZE; ++i) { - std::thread *newThread = new std::thread( + std::thread newThread( [](Internal::ThreadStackType *threadStack, std::mutex *threadStackMutex, Internal::TPQueueType *fnQueue, std::mutex *queueMutex, @@ -91,7 +91,7 @@ class ThreadPool { { std::lock_guard lock(*threadStackMutex); threadStack->push_back( - {Internal::ThreadPtr(nullptr), + {Internal::ThreadOpt{}, std::this_thread::get_id()}); } @@ -149,7 +149,7 @@ class ThreadPool { std::this_thread::sleep_for(std::chrono::microseconds(15)); } std::lock_guard stackLock(*threadStackMutex); - std::get<0>(threadStack->at(i)).reset(newThread); + std::get<0>(threadStack->at(i)) = std::move(newThread); } return pointers; } else {