Make sure the thread is interrupted when terminating.