3 ms·
Indeed. Practical example from another language. I was using a thread pool written by someone else to execute some tasks. For reasons, the tasks were essentiall
by magicalhippo 7y ago
Indeed. Practical example from another language. I was using a thread pool written by someone else to execute some tasks. For reasons, the tasks were essentially represented as shared_ptr's to an object instance.
The pool dequeued a task, issued it to a thread, the thread then called a method on the object and asked for more work.
I stumbled over a case where the destructor of the task was not always called, leaving all sorts of handles hanging.
Turned out the code that dequeued a task did so into a local variable, and didn't clear that variable after it had passed it on to the thread. So when the pool ran out of work, a reference to the last task was being held by the local variable in the pool code, and that reference was only released when new work arrived or the pool was destroyed.