By declaring the std::function<void()> task outside the scope of the worker loop the task is kept alive until the worker acquires the next task to process. This is both unnecessary and is prone to unexpected behavior for code that expects its task to be destroyed once it has finished executing. eg: binding a shared pointer to the task object.
The fix is really simple, just move the std::function<void()> task to where it is assigned.
Hi @Iunave and thanks for opening this issue! This seems like an easy enough change. I will implement it in v3.6.0, to be released within the next few weeks.
By declaring the std::function<void()> task outside the scope of the worker loop the task is kept alive until the worker acquires the next task to process. This is both unnecessary and is prone to unexpected behavior for code that expects its task to be destroyed once it has finished executing. eg: binding a shared pointer to the task object. The fix is really simple, just move the std::function<void()> task to where it is assigned.
how the new worker function would look like