exit.c

来自「这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易」· C语言 代码 · 共 72 行

C
72
字号
#include <u.h>#include <libc.h>#include <thread.h>#include "threadimpl.h"char *_threadexitsallstatus;Channel *_threadwaitchan;voidthreadexits(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();}voidthreadexitsall(char *exitstr){	Proc *p;	int pid[64];	int i, npid, mypid;	if(exitstr == nil)		exitstr = "";	_threadexitsallstatus = exitstr;	_threaddebug(DBGSCHED, "_threadexitsallstatus set to %p", _threadexitsallstatus);	mypid = getpid();	/*	 * signal others.	 * copying all the pids first avoids other threads	 * teardown procedures getting in the way.	 *	 * avoid mallocs since malloc can post a note which can	 * call threadexitsall...	 */	for(;;){		lock(&_threadpq.lock);		npid = 0;		for(p = _threadpq.head; p && npid < nelem(pid); p=p->next){			if(p->threadint == 0 && p->pid != mypid){				pid[npid++] = p->pid;				p->threadint = 1;			}		}		unlock(&_threadpq.lock);		if(npid == 0)			break;		for(i=0; i<npid; i++)			postnote(PNPROC, pid[i], "threadint");	}	/* leave */	exits(exitstr);}Channel*threadwaitchan(void){	if(_threadwaitchan==nil)		_threadwaitchan = chancreate(sizeof(Waitmsg*), 16);	return _threadwaitchan;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?