diff --git a/src/Threads.cpp b/src/Threads.cpp index 492056cb..a49eab9e 100644 --- a/src/Threads.cpp +++ b/src/Threads.cpp @@ -187,6 +187,7 @@ void CThreadPool::cancelJobs(const std::set &jobs) { continue; case CJob::DONE: + (*it)->m_eState = CJob::CANCELLED; finished.insert(*it); continue; @@ -226,8 +227,11 @@ void CThreadPool::cancelJobs(const std::set &jobs) { // Handle finished jobs. They must already be in the pipe. while (!finished.empty()) { CJob *job = getJobFromPipe(); - finishJob(job); - finished.erase(job); + if (finished.erase(job) > 0) { + assert(job->m_eState == CJob::CANCELLED); + delete job; + } else + finishJob(job); } // Delete things that still need to be deleted diff --git a/test/ThreadTest.cpp b/test/ThreadTest.cpp index 8e7a65ad..8346b21b 100644 --- a/test/ThreadTest.cpp +++ b/test/ThreadTest.cpp @@ -154,7 +154,7 @@ public: } ~CEmptyJob() { - EXPECT_FALSE(wasCancelled()); + EXPECT_TRUE(wasCancelled()); m_bDestroyed = true; }