ThreadPool
ThreadPool copied to clipboard
a
When I use your thread library, I encountered an interesting issue. Is the following conditional redundant? Because theoretically, if our thread is not in a stopped state but the task queue is empty, it shouldn't leave the waiting state.std::unique_lock<std::mutex> lock(this->queue_mutex); this->condition.wait(lock, [this]{ return this->stop || !this->tasks.empty(); }); if(this->stop && this->tasks.empty()) return;
if stop == true and tasks is empty, it will leave the waiting . This mean we were finished our tasks, then return.