From 76193d7cb0457807b2f0b95f909ab5de19480cd7 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 30 Sep 2003 17:47:42 +0000 Subject: Initial revision --- src/libthread/exit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/libthread/exit.c (limited to 'src/libthread/exit.c') diff --git a/src/libthread/exit.c b/src/libthread/exit.c new file mode 100644 index 00000000..ddf70014 --- /dev/null +++ b/src/libthread/exit.c @@ -0,0 +1,63 @@ +#include "threadimpl.h" +#include + +char *_threadexitsallstatus; +Channel *_threadwaitchan; + +void +threadexits(char *exitstr) +{ + Proc *p; + Thread *t; + + p = _threadgetproc(); + t = p->thread; + t->moribund = 1; + if(exitstr==nil) + exitstr=""; + utfecpy(p->exitstr, p->exitstr+ERRMAX, exitstr); + _sched(); +} + +void +threadexitsall(char *exitstr) +{ + Proc *p; + int *pid; + int i, npid, mypid; + + if(exitstr == nil) + exitstr = ""; + _threadexitsallstatus = exitstr; + _threaddebug(DBGSCHED, "_threadexitsallstatus set to %p", _threadexitsallstatus); + mypid = _threadgetpid(); + + /* + * signal others. + * copying all the pids first avoids other threads + * teardown procedures getting in the way. + */ + lock(&_threadpq.lock); + npid = 0; + for(p=_threadpq.head; p; p=p->next) + npid++; + pid = _threadmalloc(npid*sizeof(pid[0]), 0); + npid = 0; + for(p = _threadpq.head; p; p=p->next) + pid[npid++] = p->pid; + unlock(&_threadpq.lock); + for(i=0; i