Thanks to Sunit Pal <sunit@stanford.edu> for the question.
/* If the thread we switched from is dying, destroy its struct
thread. This must happen late so that thread_exit() doesn't
- pull out the rug under itself. */
- if (prev != NULL && prev->status == THREAD_DYING)
+ pull out the rug under itself. (We don't free
+ initial_thread because its memory was not obtained via
+ palloc().) */
+ if (prev != NULL && prev->status == THREAD_DYING && prev != initial_thread)
{
ASSERT (prev != cur);
- if (prev != initial_thread)
- palloc_free_page (prev);
+ palloc_free_page (prev);
}
}