Fix thread destruction bug.