libcore|TaskPool: Ensure pool is not deleted when the last task finishes

In taskFinished(), between remove() and isEmpty() the mutex guarding
'd' was released. This would allow ~TaskPool to finish before the
'd' is accessed again in taskFinished().