Closed thejacobpollack closed 9 years ago
There's a race condition for the shared resource task in the ThreadPool constructor. Move the variable definition outside of the infinite loop and add the C++11 thread_local storage duration specifier:
task
ThreadPool
thread_local
thread_local std::function<void()> task;
The task object is local to the lambda (and hence the thread) so no other thread even knows about it. So I'm fairly sure it is fine as it is.
You're absolutely right -- I overlooked that. I apologize.
There's a race condition for the shared resource
task
in theThreadPool
constructor. Move the variable definition outside of the infinite loop and add the C++11thread_local
storage duration specifier: