fix thread exit