Added cancel() to destructor of OptimizationTask in order to avoid dead locks.