When is it time to end a thread?