progschj / ThreadPool

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

Remove unreachable code #22

Closed elliotgoodrich closed 9 years ago

elliotgoodrich commented 9 years ago

The variable stop is only set to true in the destructor. So the only way the if statement will be executed is if you are calling enqueue on an object that has already been destructed, which is undefined behaviour

vslavik commented 9 years ago

on an object that has already been destructed

…or is being destroyed, which may be a lengthy operation — e.g. if an enqueued task tries to enqueue more.

elliotgoodrich commented 9 years ago

You're right. I had not considered threads holding references to the pool itself!

Thanks for getting back to me quickly.

vslavik commented 9 years ago

Thanks for getting back to me quickly.

@elliotgoodrich oh, I'm just another user of ThreadPool like you, sorry for not making that clear.