Reusing of ThreadPoolJob


#1

in ThreadPool::runNextJob(), a pointer to a ThreadPool is cleared before the job stops.

    job->pool = 0;
    job->shouldStop = true;
    jobs.removeValue (job);

but it isn’t cleared in ThreadPool::removeJob() and ThreadPool::removeAllJobs().
So when trying to reuse ThreadPoolJob instance removed from a ThreadPool, ThreadPool::addJob() refuses it because it has a non-zero pointer of a ThreadPool.

    jassert (job != 0);
    jassert (job->pool == 0);
    if (job->pool == 0)
    {
        // add job to pool
    }

Reusing ThreadPoolJob instances is not recommended? But I want to do because pause/resume of ThreadPool jobs are needed.


#2

I think that might just be an oversight, actually - you’re right, it ought to clear that member when the job is removed.

I don’t think I ever re-use the objects myself (which explains why I’d never have noticed this before), but there’s no reason why you can’t do so. I’ll sort it out…


#3

Thank you!
And I think in some cases it might be useful if ThreadPool can stop/start all jobs without changing a job list. (functions like suspend()/resume())