progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.64k stars 2.21k forks source link

why need to return when (this->stop && this->tasks.empty()) #33

Closed yinchunxiang closed 8 years ago

yinchunxiang commented 8 years ago

Can we just return when this->stop is true

progschj commented 8 years ago

In the long gone past this was actually how the first version worked. It changes the behaviour though. Back then I got lots of emails about how the pool wouldn't "finish his work" if it was destroyed. That can be sensible behaviour but probably shouldn't be the default. Without the emptiness check there could be enqueued tasks that get never executed... (and as a result futures that would just block indefinitely if waited on).

Darelbi commented 8 years ago

what about using a thread for "closing the pool finally once it is destroyed" ?

yinchunxiang commented 8 years ago

Got it, thanks :)