- fix thread pool bug

- cleanup byte buffer support
This commit is contained in:
2019-06-24 18:45:52 +03:00
parent 682362c6fe
commit b7524918fa
4 changed files with 260 additions and 257 deletions

View File

@@ -10,6 +10,7 @@
#include <future>
#include <functional>
#include <stdexcept>
#include <optional>
class ThreadPool
{
@@ -42,7 +43,7 @@ inline ThreadPool::ThreadPool(size_t threads)
{
for(;;)
{
std::function<void()> task;
std::function<void()> task; bool task_assigned = false;
{
std::unique_lock<std::mutex> lock(this->queue_mutex);
@@ -54,11 +55,14 @@ inline ThreadPool::ThreadPool(size_t threads)
return;
if(this->pause)
continue;
task = std::move(this->tasks.front());
this->tasks.pop();
if (this->tasks.size())
{
task = std::move(this->tasks.front()); task_assigned = true;
this->tasks.pop();
}
}
task();
if (task_assigned)
task();
}
}
);