bshoshany / thread-pool

BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
MIT License
2.21k stars 253 forks source link

[REQ] Document unexpected cleanup of tasks in worker #132

Closed BestITUserEUW closed 11 months ago

BestITUserEUW commented 11 months ago

Describe the new feature

Task cleanup in worker() is unexpectedly late. Might be helpful to add a comment to push_task that completed tasks are not cleaned up on task completion, but rather on next task received in thread or on thread function scope exit. I expected that tasks will be popped and cleaned up on completion.

Code example

An example of code that utilizes the suggested feature. Paste or write it between the two code fences.

 /**
     * @brief Push a function with zero or more arguments, but no return value, into the task queue. Does not return a future, so the user must use wait_for_tasks() or some other method to ensure that the task finishes executing, otherwise bad things will happen.
     *
     * @note Task cleanup will not be done after task completion, but rather on new task in same thread or thread scope exit
     * @tparam F The type of the function.
     * @tparam A The types of the arguments.
     * @param task The function to push.
     * @param args The zero or more arguments to pass to the function. Note that if the task is a class member function, the first argument must be a pointer to the object, i.e. &object (or this), followed by the actual arguments.
     */

Additional information

Include any additional information here.

bshoshany commented 11 months ago

Hi @BestITUserEUW and thanks for opening this issue! In v4.0.0, which will be released soon (hopefully even this week), the task is destructed as soon as it finishes executing, so this note will not be necessary.