2 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice(s), this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified other than the possible
11 * addition of one or more copyright notices.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice(s), this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/mutex.h>
38 #include <sys/resourcevar.h>
40 #include <sys/sysctl.h>
41 #include <sys/sched.h>
42 #include <sys/sleepqueue.h>
43 #include <sys/turnstile.h>
47 #include <security/audit/audit.h>
50 #include <vm/vm_extern.h>
54 * thread related storage.
56 static uma_zone_t thread_zone;
58 SYSCTL_NODE(_kern, OID_AUTO, threads, CTLFLAG_RW, 0, "thread allocation");
60 int max_threads_per_proc = 1500;
61 SYSCTL_INT(_kern_threads, OID_AUTO, max_threads_per_proc, CTLFLAG_RW,
62 &max_threads_per_proc, 0, "Limit on threads per proc");
65 SYSCTL_INT(_kern_threads, OID_AUTO, max_threads_hits, CTLFLAG_RD,
66 &max_threads_hits, 0, "");
72 TAILQ_HEAD(, thread) zombie_threads = TAILQ_HEAD_INITIALIZER(zombie_threads);
73 struct mtx zombie_lock;
74 MTX_SYSINIT(zombie_lock, &zombie_lock, "zombie lock", MTX_SPIN);
76 static void thread_zombie(struct thread *);
80 sysctl_kse_virtual_cpu(SYSCTL_HANDLER_ARGS)
89 new_val = virtual_cpu;
90 error = sysctl_handle_int(oidp, &new_val, 0, req);
91 if (error != 0 || req->newptr == NULL)
95 virtual_cpu = new_val;
100 SYSCTL_PROC(_kern_threads, OID_AUTO, virtual_cpu, CTLTYPE_INT|CTLFLAG_RW,
101 0, sizeof(virtual_cpu), sysctl_kse_virtual_cpu, "I",
102 "debug virtual cpus");
106 static struct unrhdr *tid_unrhdr;
109 * Prepare a thread for use.
112 thread_ctor(void *mem, int size, void *arg, int flags)
116 td = (struct thread *)mem;
117 td->td_state = TDS_INACTIVE;
118 td->td_oncpu = NOCPU;
120 td->td_tid = alloc_unr(tid_unrhdr);
124 * Note that td_critnest begins life as 1 because the thread is not
125 * running and is thereby implicitly waiting to be on the receiving
126 * end of a context switch.
131 audit_thread_alloc(td);
133 umtx_thread_alloc(td);
138 * Reclaim a thread after use.
141 thread_dtor(void *mem, int size, void *arg)
145 td = (struct thread *)mem;
148 /* Verify that this thread is in a safe state to free. */
149 switch (td->td_state) {
155 * We must never unlink a thread that is in one of
156 * these states, because it is currently active.
158 panic("bad state for thread unlinking");
163 panic("bad thread state");
168 audit_thread_free(td);
170 free_unr(tid_unrhdr, td->td_tid);
175 * Initialize type-stable parts of a thread (when newly created).
178 thread_init(void *mem, int size, int flags)
182 td = (struct thread *)mem;
184 vm_thread_new(td, 0);
185 cpu_thread_setup(td);
186 td->td_sleepqueue = sleepq_alloc();
187 td->td_turnstile = turnstile_alloc();
188 td->td_sched = (struct td_sched *)&td[1];
190 umtx_thread_init(td);
195 * Tear down type-stable parts of a thread (just before being discarded).
198 thread_fini(void *mem, int size)
202 td = (struct thread *)mem;
203 turnstile_free(td->td_turnstile);
204 sleepq_free(td->td_sleepqueue);
205 umtx_thread_fini(td);
206 vm_thread_dispose(td);
210 * For a newly created process,
211 * link up all the structures and its initial threads etc.
213 * {arch}/{arch}/machdep.c ia64_init(), init386() etc.
214 * proc_dtor() (should go away)
218 proc_linkup(struct proc *p, struct thread *td)
221 TAILQ_INIT(&p->p_threads); /* all threads in proc */
223 TAILQ_INIT(&p->p_upcalls); /* upcall list */
225 sigqueue_init(&p->p_sigqueue, p);
226 p->p_ksi = ksiginfo_alloc(1);
227 if (p->p_ksi != NULL) {
228 /* XXX p_ksi may be null if ksiginfo zone is not ready */
229 p->p_ksi->ksi_flags = KSI_EXT | KSI_INS;
231 LIST_INIT(&p->p_mqnotifier);
237 * Initialize global thread allocation resources.
243 mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
244 tid_unrhdr = new_unrhdr(PID_MAX + 1, INT_MAX, &tid_lock);
246 thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
247 thread_ctor, thread_dtor, thread_init, thread_fini,
250 kseinit(); /* set up kse specific stuff e.g. upcall zone*/
255 * Place an unused thread on the zombie list.
256 * Use the slpq as that must be unused by now.
259 thread_zombie(struct thread *td)
261 mtx_lock_spin(&zombie_lock);
262 TAILQ_INSERT_HEAD(&zombie_threads, td, td_slpq);
263 mtx_unlock_spin(&zombie_lock);
267 * Release a thread that has exited after cpu_throw().
270 thread_stash(struct thread *td)
272 atomic_subtract_rel_int(&td->td_proc->p_exitthreads, 1);
277 * Reap zombie kse resource.
282 struct thread *td_first, *td_next;
285 * Don't even bother to lock if none at this instant,
286 * we really don't care about the next instant..
288 if (!TAILQ_EMPTY(&zombie_threads)) {
289 mtx_lock_spin(&zombie_lock);
290 td_first = TAILQ_FIRST(&zombie_threads);
292 TAILQ_INIT(&zombie_threads);
293 mtx_unlock_spin(&zombie_lock);
295 td_next = TAILQ_NEXT(td_first, td_slpq);
296 if (td_first->td_ucred)
297 crfree(td_first->td_ucred);
298 thread_free(td_first);
311 thread_reap(); /* check if any zombies to get */
312 return (uma_zalloc(thread_zone, M_WAITOK));
317 * Deallocate a thread.
320 thread_free(struct thread *td)
323 cpu_thread_clean(td);
324 uma_zfree(thread_zone, td);
328 * Discard the current thread and exit from its context.
329 * Always called with scheduler locked.
331 * Because we can't free a thread while we're operating under its context,
332 * push the current thread into our CPU's deadthread holder. This means
333 * we needn't worry about someone else grabbing our context before we
334 * do a cpu_throw(). This may not be needed now as we are under schedlock.
335 * Maybe we can just do a thread_stash() as thr_exit1 does.
338 * libthr expects its thread exit to return for the last
339 * thread, meaning that the program is back to non-threaded
340 * mode I guess. Because we do this (cpu_throw) unconditionally
341 * here, they have their own version of it. (thr_exit1())
342 * that doesn't do it all if this was the last thread.
343 * It is also called from thread_suspend_check().
344 * Of course in the end, they end up coming here through exit1
345 * anyhow.. After fixing 'thr' to play by the rules we should be able
346 * to merge these two functions together.
353 * thread_user_enter()
356 * thread_suspend_check()
361 uint64_t new_switchtime;
369 PROC_SLOCK_ASSERT(p, MA_OWNED);
370 mtx_assert(&Giant, MA_NOTOWNED);
372 PROC_LOCK_ASSERT(p, MA_OWNED);
373 KASSERT(p != NULL, ("thread exiting without a process"));
374 CTR3(KTR_PROC, "thread_exit: thread %p (pid %ld, %s)", td,
375 (long)p->p_pid, p->p_comm);
376 KASSERT(TAILQ_EMPTY(&td->td_sigqueue.sq_list), ("signal pending"));
379 AUDIT_SYSCALL_EXIT(0, td);
383 if (td->td_standin != NULL) {
385 * Note that we don't need to free the cred here as it
386 * is done in thread_reap().
388 thread_zombie(td->td_standin);
389 td->td_standin = NULL;
393 umtx_thread_exit(td);
396 * drop FPU & debug register state storage, or any other
397 * architecture specific resources that
398 * would not be on a new untouched process.
400 cpu_thread_exit(td); /* XXXSMP */
402 /* Do the same timestamp bookkeeping that mi_switch() would do. */
403 new_switchtime = cpu_ticks();
404 p->p_rux.rux_runtime += (new_switchtime - PCPU_GET(switchtime));
405 PCPU_SET(switchtime, new_switchtime);
406 PCPU_SET(switchticks, ticks);
407 PCPU_INC(cnt.v_swtch);
408 /* Save our resource usage in our process. */
409 td->td_ru.ru_nvcsw++;
410 rucollect(&p->p_ru, &td->td_ru);
412 * The last thread is left attached to the process
413 * So that the whole bundle gets recycled. Skip
414 * all this stuff if we never had threads.
415 * EXIT clears all sign of other threads when
416 * it goes to single threading, so the last thread always
417 * takes the short path.
419 if (p->p_flag & P_HADTHREADS) {
420 if (p->p_numthreads > 1) {
428 td2 = FIRST_THREAD_IN_PROC(p);
429 sched_exit_thread(td2, td);
432 * The test below is NOT true if we are the
433 * sole exiting thread. P_STOPPED_SNGL is unset
434 * in exit1() after it is the only survivor.
436 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
437 if (p->p_numthreads == p->p_suspcount) {
438 thread_lock(p->p_singlethread);
439 thread_unsuspend_one(p->p_singlethread);
440 thread_unlock(p->p_singlethread);
444 atomic_add_int(&td->td_proc->p_exitthreads, 1);
445 PCPU_SET(deadthread, td);
448 * The last thread is exiting.. but not through exit()
450 * Theoretically this can't happen
451 * exit1() - clears threading flags before coming here
452 * kse_exit() - treats last thread specially
453 * thr_exit() - treats last thread specially
455 * thread_user_enter() - only if more exist
456 * thread_userret() - only if more exist
458 * thread_suspend_check() - only if more exist
460 panic ("thread_exit: Last thread exiting on its own");
465 /* Save our tick information with both the thread and proc locked */
466 ruxagg(&p->p_rux, td);
468 td->td_state = TDS_INACTIVE;
469 CTR1(KTR_PROC, "thread_exit: cpu_throw() thread %p", td);
471 panic("I'm a teapot!");
476 * Do any thread specific cleanups that may be needed in wait()
477 * called with Giant, proc and schedlock not held.
480 thread_wait(struct proc *p)
484 mtx_assert(&Giant, MA_NOTOWNED);
485 KASSERT((p->p_numthreads == 1), ("Multiple threads in wait1()"));
486 td = FIRST_THREAD_IN_PROC(p);
488 if (td->td_standin != NULL) {
489 if (td->td_standin->td_ucred != NULL) {
490 crfree(td->td_standin->td_ucred);
491 td->td_standin->td_ucred = NULL;
493 thread_free(td->td_standin);
494 td->td_standin = NULL;
497 /* Lock the last thread so we spin until it exits cpu_throw(). */
500 /* Wait for any remaining threads to exit cpu_throw(). */
501 while (p->p_exitthreads)
502 sched_relinquish(curthread);
503 cpu_thread_clean(td);
504 crfree(td->td_ucred);
505 thread_reap(); /* check for zombie threads etc. */
509 * Link a thread to a process.
510 * set up anything that needs to be initialized for it to
511 * be used by the process.
513 * Note that we do not link to the proc's ucred here.
514 * The thread is linked as if running but no KSE assigned.
517 * thread_schedule_upcall()
521 thread_link(struct thread *td, struct proc *p)
525 * XXX This can't be enabled because it's called for proc0 before
526 * it's spinlock has been created.
527 * PROC_SLOCK_ASSERT(p, MA_OWNED);
529 td->td_state = TDS_INACTIVE;
533 LIST_INIT(&td->td_contested);
534 sigqueue_init(&td->td_sigqueue, p);
535 callout_init(&td->td_slpcallout, CALLOUT_MPSAFE);
536 TAILQ_INSERT_HEAD(&p->p_threads, td, td_plist);
541 * Convert a process with one thread to an unthreaded process.
543 * thread_single(exit) (called from execve and exit)
544 * kse_exit() XXX may need cleaning up wrt KSE stuff
547 thread_unthread(struct thread *td)
549 struct proc *p = td->td_proc;
551 KASSERT((p->p_numthreads == 1), ("Unthreading with >1 threads"));
554 p->p_flag &= ~(P_SA|P_HADTHREADS);
555 td->td_mailbox = NULL;
556 td->td_pflags &= ~(TDP_SA | TDP_CAN_UNBIND);
557 if (td->td_standin != NULL) {
558 thread_zombie(td->td_standin);
559 td->td_standin = NULL;
562 p->p_flag &= ~P_HADTHREADS;
571 thread_unlink(struct thread *td)
573 struct proc *p = td->td_proc;
575 PROC_SLOCK_ASSERT(p, MA_OWNED);
576 TAILQ_REMOVE(&p->p_threads, td, td_plist);
578 /* could clear a few other things here */
579 /* Must NOT clear links to proc! */
583 * Enforce single-threading.
585 * Returns 1 if the caller must abort (another thread is waiting to
586 * exit the process or similar). Process is locked!
587 * Returns 0 when you are successfully the only thread running.
588 * A process has successfully single threaded in the suspend mode when
589 * There are no threads in user mode. Threads in the kernel must be
590 * allowed to continue until they get to the user boundary. They may even
591 * copy out their return values and data before suspending. They may however be
592 * accelerated in reaching the user boundary as we will wake up
593 * any sleeping threads that are interruptable. (PCATCH).
596 thread_single(int mode)
605 mtx_assert(&Giant, MA_NOTOWNED);
606 PROC_LOCK_ASSERT(p, MA_OWNED);
607 KASSERT((td != NULL), ("curthread is NULL"));
609 if ((p->p_flag & P_HADTHREADS) == 0)
612 /* Is someone already single threading? */
613 if (p->p_singlethread != NULL && p->p_singlethread != td)
616 if (mode == SINGLE_EXIT) {
617 p->p_flag |= P_SINGLE_EXIT;
618 p->p_flag &= ~P_SINGLE_BOUNDARY;
620 p->p_flag &= ~P_SINGLE_EXIT;
621 if (mode == SINGLE_BOUNDARY)
622 p->p_flag |= P_SINGLE_BOUNDARY;
624 p->p_flag &= ~P_SINGLE_BOUNDARY;
626 p->p_flag |= P_STOPPED_SINGLE;
628 p->p_singlethread = td;
629 if (mode == SINGLE_EXIT)
630 remaining = p->p_numthreads;
631 else if (mode == SINGLE_BOUNDARY)
632 remaining = p->p_numthreads - p->p_boundary_count;
634 remaining = p->p_numthreads - p->p_suspcount;
635 while (remaining != 1) {
636 if (P_SHOULDSTOP(p) != P_STOPPED_SINGLE)
638 FOREACH_THREAD_IN_PROC(p, td2) {
642 td2->td_flags |= TDF_ASTPENDING;
643 if (TD_IS_INHIBITED(td2)) {
646 if (td->td_flags & TDF_DBSUSPEND)
647 td->td_flags &= ~TDF_DBSUSPEND;
648 if (TD_IS_SUSPENDED(td2))
649 thread_unsuspend_one(td2);
650 if (TD_ON_SLEEPQ(td2) &&
651 (td2->td_flags & TDF_SINTR))
652 sleepq_abort(td2, EINTR);
654 case SINGLE_BOUNDARY:
655 if (TD_IS_SUSPENDED(td2) &&
656 !(td2->td_flags & TDF_BOUNDARY))
657 thread_unsuspend_one(td2);
658 if (TD_ON_SLEEPQ(td2) &&
659 (td2->td_flags & TDF_SINTR))
660 sleepq_abort(td2, ERESTART);
663 if (TD_IS_SUSPENDED(td2)) {
668 * maybe other inhibited states too?
670 if ((td2->td_flags & TDF_SINTR) &&
671 (td2->td_inhibitors &
672 (TDI_SLEEPING | TDI_SWAPPED)))
673 thread_suspend_one(td2);
678 else if (TD_IS_RUNNING(td2) && td != td2) {
684 if (mode == SINGLE_EXIT)
685 remaining = p->p_numthreads;
686 else if (mode == SINGLE_BOUNDARY)
687 remaining = p->p_numthreads - p->p_boundary_count;
689 remaining = p->p_numthreads - p->p_suspcount;
692 * Maybe we suspended some threads.. was it enough?
699 * Wake us up when everyone else has suspended.
700 * In the mean time we suspend as well.
702 thread_suspend_switch(td);
703 if (mode == SINGLE_EXIT)
704 remaining = p->p_numthreads;
705 else if (mode == SINGLE_BOUNDARY)
706 remaining = p->p_numthreads - p->p_boundary_count;
708 remaining = p->p_numthreads - p->p_suspcount;
710 if (mode == SINGLE_EXIT) {
712 * We have gotten rid of all the other threads and we
713 * are about to either exit or exec. In either case,
714 * we try our utmost to revert to being a non-threaded
717 p->p_singlethread = NULL;
718 p->p_flag &= ~(P_STOPPED_SINGLE | P_SINGLE_EXIT);
726 * Called in from locations that can safely check to see
727 * whether we have to suspend or at least throttle for a
728 * single-thread event (e.g. fork).
730 * Such locations include userret().
731 * If the "return_instead" argument is non zero, the thread must be able to
732 * accept 0 (caller may continue), or 1 (caller must abort) as a result.
734 * The 'return_instead' argument tells the function if it may do a
735 * thread_exit() or suspend, or whether the caller must abort and back
738 * If the thread that set the single_threading request has set the
739 * P_SINGLE_EXIT bit in the process flags then this call will never return
740 * if 'return_instead' is false, but will exit.
742 * P_SINGLE_EXIT | return_instead == 0| return_instead != 0
743 *---------------+--------------------+---------------------
744 * 0 | returns 0 | returns 0 or 1
745 * | when ST ends | immediatly
746 *---------------+--------------------+---------------------
747 * 1 | thread exits | returns 1
749 * 0 = thread_exit() or suspension ok,
750 * other = return error instead of stopping the thread.
752 * While a full suspension is under effect, even a single threading
753 * thread would be suspended if it made this call (but it shouldn't).
754 * This call should only be made from places where
755 * thread_exit() would be safe as that may be the outcome unless
756 * return_instead is set.
759 thread_suspend_check(int return_instead)
766 mtx_assert(&Giant, MA_NOTOWNED);
767 PROC_LOCK_ASSERT(p, MA_OWNED);
768 while (P_SHOULDSTOP(p) ||
769 ((p->p_flag & P_TRACED) && (td->td_flags & TDF_DBSUSPEND))) {
770 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
771 KASSERT(p->p_singlethread != NULL,
772 ("singlethread not set"));
774 * The only suspension in action is a
775 * single-threading. Single threader need not stop.
776 * XXX Should be safe to access unlocked
777 * as it can only be set to be true by us.
779 if (p->p_singlethread == td)
780 return (0); /* Exempt from stopping. */
782 if ((p->p_flag & P_SINGLE_EXIT) && return_instead)
785 /* Should we goto user boundary if we didn't come from there? */
786 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE &&
787 (p->p_flag & P_SINGLE_BOUNDARY) && return_instead)
790 /* If thread will exit, flush its pending signals */
791 if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td))
792 sigqueue_flush(&td->td_sigqueue);
797 * If the process is waiting for us to exit,
798 * this thread should just suicide.
799 * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE.
801 if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td))
803 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
804 if (p->p_numthreads == p->p_suspcount + 1) {
805 thread_lock(p->p_singlethread);
806 thread_unsuspend_one(p->p_singlethread);
807 thread_unlock(p->p_singlethread);
813 * When a thread suspends, it just
814 * gets taken off all queues.
816 thread_suspend_one(td);
817 if (return_instead == 0) {
818 p->p_boundary_count++;
819 td->td_flags |= TDF_BOUNDARY;
822 mi_switch(SW_INVOL, NULL);
823 if (return_instead == 0)
824 td->td_flags &= ~TDF_BOUNDARY;
827 if (return_instead == 0)
828 p->p_boundary_count--;
834 thread_suspend_switch(struct thread *td)
839 KASSERT(!TD_IS_SUSPENDED(td), ("already suspended"));
840 PROC_LOCK_ASSERT(p, MA_OWNED);
841 PROC_SLOCK_ASSERT(p, MA_OWNED);
843 * We implement thread_suspend_one in stages here to avoid
844 * dropping the proc lock while the thread lock is owned.
850 TD_SET_SUSPENDED(td);
853 mi_switch(SW_VOL, NULL);
861 thread_suspend_one(struct thread *td)
863 struct proc *p = td->td_proc;
865 PROC_SLOCK_ASSERT(p, MA_OWNED);
866 THREAD_LOCK_ASSERT(td, MA_OWNED);
867 KASSERT(!TD_IS_SUSPENDED(td), ("already suspended"));
869 TD_SET_SUSPENDED(td);
873 thread_unsuspend_one(struct thread *td)
875 struct proc *p = td->td_proc;
877 PROC_SLOCK_ASSERT(p, MA_OWNED);
878 THREAD_LOCK_ASSERT(td, MA_OWNED);
879 KASSERT(TD_IS_SUSPENDED(td), ("Thread not suspended"));
880 TD_CLR_SUSPENDED(td);
886 * Allow all threads blocked by single threading to continue running.
889 thread_unsuspend(struct proc *p)
893 PROC_LOCK_ASSERT(p, MA_OWNED);
894 PROC_SLOCK_ASSERT(p, MA_OWNED);
895 if (!P_SHOULDSTOP(p)) {
896 FOREACH_THREAD_IN_PROC(p, td) {
898 if (TD_IS_SUSPENDED(td)) {
899 thread_unsuspend_one(td);
903 } else if ((P_SHOULDSTOP(p) == P_STOPPED_SINGLE) &&
904 (p->p_numthreads == p->p_suspcount)) {
906 * Stopping everything also did the job for the single
907 * threading request. Now we've downgraded to single-threaded,
910 thread_lock(p->p_singlethread);
911 thread_unsuspend_one(p->p_singlethread);
912 thread_unlock(p->p_singlethread);
917 * End the single threading mode..
920 thread_single_end(void)
927 PROC_LOCK_ASSERT(p, MA_OWNED);
928 p->p_flag &= ~(P_STOPPED_SINGLE | P_SINGLE_EXIT | P_SINGLE_BOUNDARY);
930 p->p_singlethread = NULL;
932 * If there are other threads they mey now run,
933 * unless of course there is a blanket 'stop order'
934 * on the process. The single threader must be allowed
935 * to continue however as this is a bad place to stop.
937 if ((p->p_numthreads != 1) && (!P_SHOULDSTOP(p))) {
938 FOREACH_THREAD_IN_PROC(p, td) {
940 if (TD_IS_SUSPENDED(td)) {
941 thread_unsuspend_one(td);
950 thread_find(struct proc *p, lwpid_t tid)
954 PROC_LOCK_ASSERT(p, MA_OWNED);
956 FOREACH_THREAD_IN_PROC(p, td) {
957 if (td->td_tid == tid)