⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
/*Threadmain spawns two subprocesses, oneto read the mouse, and one to receivetimer events.  The events are sent via achannel to the main proc which prints aword when an event comes in.  When mousebutton three is pressed, the applicationterminates.*/#include <u.h>#include <libc.h>#include <thread.h>enum{	STACK = 2048,};voidmouseproc(void *arg){	char m[48];	int mfd;	Channel *mc;	mc = arg;	if((mfd = open("/dev/mouse", OREAD)) < 0)		sysfatal("open /dev/mouse: %r\en");	for(;;){		if(read(mfd, m, sizeof m) != sizeof m)			sysfatal("eof");		if(atoi(m+1+2*12)&4)			sysfatal("button 3");		send(mc, m);	}}voidclockproc(void *arg){	int t;	Channel *c;	c = arg;	for(t=0;; t++){		sleep(1000);		sendul(c, t);	}}voidthreadmain(int argc, char *argv[]){	char m[48];	int t;	Alt a[] = {	/*	 c		v		op   */		{nil,	m,	CHANRCV},		{nil,	&t,	CHANRCV},		{nil,	nil,	CHANEND},	};	/* create mouse event channel and mouse process */	a[0].c = chancreate(sizeof m, 0);	proccreate(mouseproc, a[0].c, STACK);	/* create clock event channel and clock process */	a[1].c = chancreate(sizeof(ulong), 0);	/* clock event channel */	proccreate(clockproc, a[1].c, STACK);	for(;;){		switch(alt(a)){		case 0:	/*mouse event */			fprint(2, "click ");			break;		case 1:	/* clock event */			fprint(2, "tic ");			break;		default:			sysfatal("can't happen");		}	}}

⌨️ 快捷键说明

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