时间片轮转 操作系统课程设计 myprocess.doc
上传人:qw****27 上传时间:2024-09-12 格式:DOC 页数:11 大小:52KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

时间片轮转 操作系统课程设计 myprocess.doc

时间片轮转操作系统课程设计myprocess.doc

预览

免费试读已结束,剩余 1 页请下载文档后查看

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include<stdio.h>#include<stdlib.h>#include<dos.h>#include<string.h>/*状态码*/#defineNTCB5/*TCB的数量*/#defineNTEXT60/*线程通信缓冲区文本内容的大小*/#defineNBUF10/*缓冲区的个数*//****线程的五种状态****/#defineSTART-1#defineFINISHED0#defineRUNNING1#defineREADY2#defineBLOCKED3#definetimeout1/*线程时间片轮转的时间*/typedefint(far*codeptr)(void);/*函数指针定义*//*DOS的初始化状态码*/#defineGET_INDOS0x34#defineGET_CRIT_ERR0x5d06structbuffer{intsender;intsize;chartext[NTEXT];structbuffer*next;}*freebuff;/*消息缓冲区的定义*/typedefstruct{intvalue;structTCB*wq;}semaphore;/*记录型信号量定义*/structTCB{unsignedchar*stack;unsignedss;unsignedsp;charstate;charname[10];structbuffer*mq;/*消息队列排队使用*/semaphoremutex;/*互斥信号量,用于对TCB消息队列处理时互斥*/semaphoresm;/*消息队列的计数信号亮*/structTCB*next;}tcb[NTCB];/*线程控制块定义*/structint_regs{unsignedbp;unsigneddi;unsignedsi;unsignedds;unsignedes;unsigneddx;unsignedcx;unsignedbx;unsignedax;unsignedip;unsignedcs;unsignedflags;unsignedoff;unsignedseg;};/*线程私有堆栈的数据结构的定义*/charfar*indos_ptr=0;charfar*crit_err_ptr=0;unionREGSregs;structSREGSsegregs;intcurrenttcb=-1;/*初始化TCB的值*/inttimecount=0;/*时间计数初始为0*/semaphoresfb={NBUF,NULL};/*空闲缓冲区的同步信号量*/semaphoremutexfb={1,NULL};/*对空闲缓冲区处理的互斥信号量*/semaphorefmutex={0,NULL};/*F1和F2的同步信号量*/voidInitBuff(void);/*初始化消息缓冲区*/intDosBusy(void);/*DosBusyFunctionreturnnon_zeroifDOSisbusy*/voidInitInDos(void);/*InitInDosFuntiontogettheaddressesofINDOSandCRIT_ERRflags*/voidInitTcb(void);/*初始化TCB*/voidinterrupt(*old_int8)(void);/*旧的时钟中断处理程序*/voidinterruptnew_int8(void);/*新的时钟中断处理程序*/intcreate(char*name,codeptrcode,intstacklen);/*创建线程*/voidtcb_state(void);/*线程状态函数*/intSeeknext(void);/*寻找下一个就绪线程*/voidinterruptcpu_switch(void);/*CPU调度函数*/intall_finished();/*判断所有线程是否完成*/voidDestroy(inti);/*销毁一个线程*/voidover(void);/*结束一个线程*/voidwait(semaphore*sem);/*P操作*/voidsignal(semaphore*sem);/*v操作*/voidblock(structTCB**qp);/*阻塞函数*/voidwakeup(structTCB**qp);/*唤醒函数*/voidf1(void);/*函数F1*/voidf2(void);/*函数F2*/