Unlock mutex on thread cancellation