--- src/sys/kern/kern_exit.c 2007/08/30 20:41:00 1.86 +++ src/sys/kern/kern_exit.c 2008/03/20 03:59:10 1.87 @@ -735,6 +735,16 @@ loop: nfound++; if (p->p_stat == SZOMB) { /* + * We may go into SZOMB with threads still present. + * We must wait for them to exit before we can reap + * the master thread, otherwise we may race reaping + * non-master threads. + */ + while (p->p_nthreads > 0) { + tsleep(&p->p_nthreads, 0, "lwpzomb", hz); + } + + /* * Reap any LWPs left in p->p_lwps. This is usually * just the last LWP. This must be done before * we loop on p_lock since the lwps hold a ref on