Implement quitting thread.