What causes a thread to be closed?