Use locks to wait for the task finish