Fixed crash on thread exit.