-
Notifications
You must be signed in to change notification settings - Fork 128
Open
Description
Currently, ThreadPool's destructor does not wait for completion of all tasks posted to it, because Worker relies on m_running_flag to stay in the loop, as a result this flag is set to false as soon as ThreadPool destructor is invoked, as the threads exit without further processing the tasks from the queue.
One solution is to remove m_running_flag from the worker, and instead add a poison task to the queue and each worker reads this poison task and exit but before exiting enqueue it again, so that other workers can exit in similar mannner.
Also, ThreadPool may provide a function called wait() function which will add the poison task. Also, the destructor should call this wait() function.
talhasaruhan
Metadata
Metadata
Assignees
Labels
No labels