Closed loveyacper closed 3 years ago
Have you actually seen this supposed issue happen? My reading of
this->condition.wait(lock,
[this]{ return this->stop || !this->tasks.empty(); });
Is that it should first check the condition in the supplied lambda and only if that is not satisfied, loop and wait.
Sorry... Yes, the wait condition (return this->stop) can avoid hang
I add some code for expand thread pool runtime. Suppose all worker threads are executing tasks, now you enqueue new task, it won't be executed immediately, I modified it to create new worker in this case.
I think we need make "notify_all" in lock guard to avoid this issue
不用整很多高大上的编译上的东西,弄好性能就行。
Under given conditions, worker thread may be suspended
The main thread destruct pool instance:
In worker thread, insert a statement to sleep make the problem happen: