We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 588b59c commit 0fb9215Copy full SHA for 0fb9215
ThreadPool.h
@@ -40,14 +40,18 @@ inline ThreadPool::ThreadPool(size_t threads)
40
{
41
for(;;)
42
43
- std::unique_lock<std::mutex> lock(this->queue_mutex);
44
- while(!this->stop && this->tasks.empty())
45
- this->condition.wait(lock);
46
- if(this->stop && this->tasks.empty())
47
- return;
48
- std::function<void()> task(this->tasks.front());
49
- this->tasks.pop();
50
- lock.unlock();
+ std::function<void()> task;
+
+ {
+ std::unique_lock<std::mutex> lock(this->queue_mutex);
+ while(!this->stop && this->tasks.empty())
+ this->condition.wait(lock);
+ if(this->stop && this->tasks.empty())
+ return;
51
+ task = std::move(this->tasks.front());
52
+ this->tasks.pop();
53
+ }
54
55
task();
56
}
57
0 commit comments