Fix threadpool name use-after-free bug

This commit is contained in:
Nikita Lisitsa 2020-11-21 15:31:25 +03:00
parent 240d26663b
commit fb9f1d8f30

View file

@ -20,9 +20,10 @@ namespace psemek::util
{ {
for (std::size_t th = 0; th < thread_count; ++th) for (std::size_t th = 0; th < thread_count; ++th)
{ {
threads_.emplace_back([this, &name, th, thread_count] std::string tname = thread_count == 1 ? name : to_string(name, '#', th);
threads_.emplace_back([this, tname = std::move(tname), th, thread_count]
{ {
log::register_thread(thread_count == 1 ? name : to_string(name, '#', th)); log::register_thread(tname);
for (bool running = true; running;) for (bool running = true; running;)
{ {
auto task = task_queue_.pop(); auto task = task_queue_.pop();