資源描述:
《時(shí)間片輪轉(zhuǎn) 操作系統(tǒng)課程設(shè)計(jì) myprocess》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、#include#include#include#include/*狀態(tài)碼*/#defineNTCB5/*TCB的數(shù)量*/#defineNTEXT60/*線程通信緩沖區(qū)文本內(nèi)容的大小*/#defineNBUF10/*緩沖區(qū)的個(gè)數(shù)*//****線程的五種狀態(tài)****/#defineSTART-1#defineFINISHED0#defineRUNNING1#defineREADY2#defineBLOCKED3#definetimeout1/*線程時(shí)間片輪轉(zhuǎn)的時(shí)間*/
2、typedefint(far*codeptr)(void);/*函數(shù)指針定義*//*DOS的初始化狀態(tài)碼*/#defineGET_INDOS0x34#defineGET_CRIT_ERR0x5d06structbuffer{intsender;intsize;chartext[NTEXT];structbuffer*next;}*freebuff;/*消息緩沖區(qū)的定義*/typedefstruct{intvalue;structTCB*wq;}semaphore;/*記錄型信號(hào)量定義*/structTCB{unsignedchar*st
3、ack;unsignedss;unsignedsp;charstate;charname[10];structbuffer*mq;/*消息隊(duì)列排隊(duì)使用*/semaphoremutex;/*互斥信號(hào)量,用于對(duì)TCB消息隊(duì)列處理時(shí)互斥*/semaphoresm;/*消息隊(duì)列的計(jì)數(shù)信號(hào)亮*/structTCB*next;}tcb[NTCB];/*線程控制塊定義*/structint_regs{unsignedbp;unsigneddi;unsignedsi;unsignedds;unsignedes;unsigneddx;unsignedcx
4、;unsignedbx;unsignedax;unsignedip;unsignedcs;unsignedflags;unsignedoff;unsignedseg;};/*線程私有堆棧的數(shù)據(jù)結(jié)構(gòu)的定義*/charfar*indos_ptr=0;charfar*crit_err_ptr=0;unionREGSregs;structSREGSsegregs;intcurrenttcb=-1;/*初始化TCB的值*/inttimecount=0;/*時(shí)間計(jì)數(shù)初始為0*/semaphoresfb={NBUF,NULL};/*空閑緩沖區(qū)的同步信
5、號(hào)量*/semaphoremutexfb={1,NULL};/*對(duì)空閑緩沖區(qū)處理的互斥信號(hào)量*/semaphorefmutex={0,NULL};/*F1和F2的同步信號(hào)量*/voidInitBuff(void);/*初始化消息緩沖區(qū)*/intDosBusy(void);/*DosBusyFunctionreturnnon_zeroifDOSisbusy*/voidInitInDos(void);/*InitInDosFuntiontogettheaddressesofINDOSandCRIT_ERRflags*/voidInitTcb
6、(void);/*初始化TCB*/voidinterrupt(*old_int8)(void);/*舊的時(shí)鐘中斷處理程序*/voidinterruptnew_int8(void);/*新的時(shí)鐘中斷處理程序*/intcreate(char*name,codeptrcode,intstacklen);/*創(chuàng)建線程*/voidtcb_state(void);/*線程狀態(tài)函數(shù)*/intSeeknext(void);/*尋找下一個(gè)就緒線程*/voidinterruptcpu_switch(void);/*CPU調(diào)度函數(shù)*/intall_finis
7、hed();/*判斷所有線程是否完成*/voidDestroy(inti);/*銷毀一個(gè)線程*/voidover(void);/*結(jié)束一個(gè)線程*/voidwait(semaphore*sem);/*P操作*/voidsignal(semaphore*sem);/*v操作*/voidblock(structTCB**qp);/*阻塞函數(shù)*/voidwakeup(structTCB**qp);/*喚醒函數(shù)*/voidf1(void);/*函數(shù)F1*/voidf2(void);/*函數(shù)F2*/voidinsert(structbuffer**
8、mq,structbuffer*buff);/*將buff所指的緩沖區(qū)插到*mq所指的緩沖隊(duì)列末尾*/voidsend(char*receiver,char*a,intsize);/*發(fā)送一個(gè)消息給rece