Blob


1 #include "threadimpl.h"
2 #include <signal.h>
4 char *_threadexitsallstatus;
5 Channel *_threadwaitchan;
7 void
8 threadexits(char *exitstr)
9 {
10 Proc *p;
11 Thread *t;
13 p = _threadgetproc();
14 t = p->thread;
15 t->moribund = 1;
16 if(exitstr==nil)
17 exitstr="";
18 utfecpy(p->exitstr, p->exitstr+ERRMAX, exitstr);
19 _sched();
20 }
22 void
23 threadexitsall(char *exitstr)
24 {
25 Proc *p;
26 int *pid;
27 int i, npid, mypid;
29 if(exitstr == nil)
30 exitstr = "";
31 _threadexitsallstatus = exitstr;
32 _threaddebug(DBGSCHED, "_threadexitsallstatus set to %p", _threadexitsallstatus);
33 mypid = _threadgetpid();
35 /*
36 * signal others.
37 * copying all the pids first avoids other threads
38 * teardown procedures getting in the way.
39 */
40 lock(&_threadpq.lock);
41 npid = 0;
42 for(p=_threadpq.head; p; p=p->next)
43 npid++;
44 pid = _threadmalloc(npid*sizeof(pid[0]), 0);
45 npid = 0;
46 for(p = _threadpq.head; p; p=p->next)
47 pid[npid++] = p->pid;
48 unlock(&_threadpq.lock);
49 for(i=0; i<npid; i++)
50 if(pid[i] != mypid)
51 kill(pid[i], SIGTERM);
53 /* leave */
54 exit(0);
55 }
57 Channel*
58 threadwaitchan(void)
59 {
60 if(_threadwaitchan==nil)
61 _threadwaitchan = chancreate(sizeof(Waitmsg*), 16);
62 return _threadwaitchan;
63 }