fix thread shutdown process