Fix crash in thread stop