ThreadPoolJob Memory Management

Hello Julian, let’s say I have 3 threads assigned to a ThreadPool and I add 10 jobs to the Pool. 3 are now active and can return


The other 7 however are inactive and removeAllJobs will just remove them from the Array without deletion.

Is there any chance you could expand removeAllJobs so that…

bool removeAllJobs (const bool interruptRunningJobs,
const int timeOutMilliseconds,bool deleteInactiveJobs=false);

[code]bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
const int timeOutMs,bool deleteInactiveJobs)

for (int i = jobs.size(); --i >= 0;)
    ThreadPoolJob* const job = (ThreadPoolJob*) jobs.getUnchecked(i);

    if (job->isActive)
        if (interruptRunningJobs)
        jobs.remove (i);
		if (deleteInactiveJobs)
			delete job;


const uint32 start = Time::getMillisecondCounter();

while (jobs.size() > 0)
    if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
        return false;

    Thread::sleep (2);

return true;


That way we can just call removeAllJobs(true,4000,true); in our Destructor and know the jobs are going to be deleted properly. (Or give me access to the lock!)



Yes - that does seem like a really sensible idea, thanks!