Use null util::function instead of a stop_execution exception when stopping threadpool threads to prevent exceptions from triggering when debugging
This commit is contained in:
parent
5e7a9b7697
commit
059b2b1539
3 changed files with 5 additions and 15 deletions
|
|
@ -4,7 +4,6 @@
|
|||
#include <psemek/util/function.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
namespace psemek::async
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <psemek/util/thread.hpp>
|
||||
#include <psemek/util/synchronyzed_queue.hpp>
|
||||
|
||||
#include <future>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
|
|
|||
|
|
@ -9,13 +9,6 @@
|
|||
namespace psemek::async
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct stop_execution{};
|
||||
|
||||
}
|
||||
|
||||
threadpool::threadpool(std::string const & name, std::size_t thread_count)
|
||||
: working_count_{0}
|
||||
{
|
||||
|
|
@ -25,10 +18,13 @@ namespace psemek::async
|
|||
threads_.emplace_back([this, tname = std::move(tname)]() mutable
|
||||
{
|
||||
log::thread_registrator reg(std::move(tname));
|
||||
for (bool running = true; running;)
|
||||
while (true)
|
||||
{
|
||||
auto task = task_queue_.pop();
|
||||
|
||||
if (!task)
|
||||
break;
|
||||
|
||||
{
|
||||
std::lock_guard lock{working_count_mutex_};
|
||||
++working_count_;
|
||||
|
|
@ -38,10 +34,6 @@ namespace psemek::async
|
|||
{
|
||||
task();
|
||||
}
|
||||
catch (stop_execution const &)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
catch (util::exception const & e)
|
||||
{
|
||||
log::error() << "Unhandled exception in threadpool executor: " << e;
|
||||
|
|
@ -86,7 +78,7 @@ namespace psemek::async
|
|||
for (auto const & thread: threads_)
|
||||
{
|
||||
unused(thread);
|
||||
task_queue_.push([]{ throw stop_execution{}; });
|
||||
task_queue_.push(nullptr);
|
||||
}
|
||||
threads_.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue