If you are passing the object to a worker thread, you can't create it on the stack. By the time the worker thread invokes it, the parent thread has likely left that function and destroyed the object. You need to dynamically allocate (perhaps via new
) it in the parent thread and only free (delete
) it in the worker thread after you're done with it.
As another note, you need locking around your queue accesses if the parent is able to enqueue a job while the worker is running.