Move thread exit code into kernel