The thread could still be running on its stack whenever the stack ends up getting reaped, which would free and reuse the stack before it stops being used. Lock and unlock the thread to wait until it finishes switching.