Index: sys/proc.h =================================================================== --- sys/proc.h (revision 213714) +++ sys/proc.h (working copy) @@ -353,7 +353,7 @@ #define TDF_NEEDRESCHED 0x00010000 /* Thread needs to yield. */ #define TDF_NEEDSIGCHK 0x00020000 /* Thread may need signal delivery. */ #define TDF_NOLOAD 0x00040000 /* Ignore during load avg calculations. */ -#define TDF_TIDHASH 0x00080000 /* Thread is on hash table. */ +#define TDF_UNUSED19 0x00080000 /* --available-- */ #define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */ #define TDF_UNUSED21 0x00200000 /* --available-- */ #define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */ Index: kern/kern_thread.c =================================================================== --- kern/kern_thread.c (revision 213714) +++ kern/kern_thread.c (working copy) @@ -746,25 +746,23 @@ (p->p_flag & P_SINGLE_BOUNDARY) && return_instead) return (ERESTART); - /* If thread will exit, flush its pending signals */ - if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) - sigqueue_flush(&td->td_sigqueue); - - PROC_SLOCK(p); - thread_stopped(p); /* * If the process is waiting for us to exit, * this thread should just suicide. * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE. */ if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) { - PROC_SUNLOCK(p); PROC_UNLOCK(p); tidhash_remove(td); PROC_LOCK(p); + tdsigcleanup(td); PROC_SLOCK(p); + thread_stopped(p); thread_exit(); } + + PROC_SLOCK(p); + thread_stopped(p); if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) { if (p->p_numthreads == p->p_suspcount + 1) { thread_lock(p->p_singlethread); @@ -981,12 +979,7 @@ tidhash_add(struct thread *td) { rw_wlock(&tidhash_lock); - thread_lock(td); - if ((td->td_flags & TDF_TIDHASH) == 0) { - LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); - td->td_flags |= TDF_TIDHASH; - } - thread_unlock(td); + LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); rw_wunlock(&tidhash_lock); } @@ -994,11 +987,6 @@ tidhash_remove(struct thread *td) { rw_wlock(&tidhash_lock); - thread_lock(td); - if ((td->td_flags & TDF_TIDHASH) != 0) { - LIST_REMOVE(td, td_hash); - td->td_flags &= ~TDF_TIDHASH; - } - thread_unlock(td); + LIST_REMOVE(td, td_hash); rw_wunlock(&tidhash_lock); } Index: kern/kern_thr.c =================================================================== --- kern/kern_thr.c (revision 213657) +++ kern/kern_thr.c (working copy) @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -285,23 +285,23 @@ kern_umtx_wake(td, uap->state, INT_MAX, 0); } - tidhash_remove(td); - + rw_wlock(&tidhash_lock); PROC_LOCK(p); - tdsigcleanup(td); - PROC_SLOCK(p); - /* * Shutting down last thread in the proc. This will actually * call exit() in the trampoline when it returns. */ if (p->p_numthreads != 1) { + LIST_REMOVE(td, td_hash); + rw_wunlock(&tidhash_lock); + tdsigcleanup(td); + PROC_SLOCK(p); thread_stopped(p); thread_exit(); /* NOTREACHED */ } - PROC_SUNLOCK(p); PROC_UNLOCK(p); + rw_wunlock(&tidhash_lock); return (0); } Index: kern/init_main.c =================================================================== --- kern/init_main.c (revision 213657) +++ kern/init_main.c (working copy) @@ -443,7 +443,6 @@ */ LIST_INSERT_HEAD(&allproc, p, p_list); LIST_INSERT_HEAD(PIDHASH(0), p, p_hash); - LIST_INSERT_HEAD(TIDHASH(0), td, td_hash); mtx_init(&pgrp0.pg_mtx, "process group", NULL, MTX_DEF | MTX_DUPOK); p->p_pgrp = &pgrp0; LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash); @@ -462,6 +461,7 @@ STAILQ_INIT(&p->p_ktr); p->p_nice = NZERO; td->td_tid = PID_MAX + 1; + LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); td->td_state = TDS_RUNNING; td->td_pri_class = PRI_TIMESHARE; td->td_user_pri = PUSER; Index: kern/kern_kthread.c =================================================================== --- kern/kern_kthread.c (revision 213657) +++ kern/kern_kthread.c (working copy) @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -315,17 +316,20 @@ p = curthread->td_proc; - tidhash_remove(curthread); /* A module may be waiting for us to exit. */ wakeup(curthread); + rw_wlock(&tidhash_lock); PROC_LOCK(p); if (p->p_numthreads == 1) { PROC_UNLOCK(p); + rw_wunlock(&tidhash_lock); kproc_exit(0); /* NOTREACHED. */ } + LIST_REMOVE(curthread, td_hash); + rw_wunlock(&tidhash_lock); PROC_SLOCK(p); thread_exit(); }