操作系统期末复习资料(知识点汇总)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

11:23CPU4I/O56781.223N1/N1/N491CPUCPU23I/OCPU451012C/S3:3412--3PCBPCB4CPUCPUCPUI/0I/OPCBPCBPCB5PCBPCBPCB412341PCB2PCBPCB5PCB1PCBPCB2.345.PCBblockPCBPCB5612-/**/#includestdio.h#defineMAX10typedefstructqueue{intbuffer[MAX];intfront;intrear;}queue;voidproducer(queue&q,intdata){if(isfull(q)==1){//}else{enqueue(q,data));}}voidcustomer(queue&q){if(isempty(q)==1){//}else{intdata=outqueue(q);}}364Swait(),signal()PVvoidwait(ints){while(s=0)//;s=s-1;//}voidsignal(ints){s=s+1;//}S=0valueLs=0//typedefstructsemaphore{intvalue;//structsemaphore*L;//}semaphore;voidwait(semaphore&s){//valuewaits.value=s.value-1;//valueif(s.value0)block(s.L);//block//value}voidsignal(semaphore&s){s.value=s.value+1;if(s.value=0)//value.wakeup(s.L);}value1ANDANDANDtypedefstructsource{intarr[MAX];//sourceintlength;//}source;7voidsignal(source&s){for(inti=0;is.length;i++)s.arr[i]++;//}voidwait(source&s){intflag=0;for(inti=0;is.length;i++){if(s.arr[i]=1)//flag=1;else{flag=0;break;}}if(flag==1){//for(inti=0;is.length;i++)s.arr[i]--;}else{}}1mutex,1waitmutexsignal(mutex)waitsignal25publicclassMonitor{privateintlocal_value;privatestringmonitor_name;privatevoidinit_value();privatevoiduse_value();publicvoidpublic_use_value();};1PCB8234566.-voidinit(semaphore&s){s.empty=MAX;s.full=0;s.mutex=1;}//voidproducer(queue&q,semaphore&s){wait(s.empty);//wait(s.mutex);//enqueue(q,data);signal(s.mutex);signal(s.full);}voidcustomer(queue&q,semaphore&s){wait(s.full);wait(s.mutex);outqueue(q);signal(s.mutex);signal(s.empty);}-P,VP,VPAND-waitsignalswait(),signal()wait(s.full);wait(s.mutex);Swait(full,mutex);//N==5//ivoidprofess(semaphore&s){//wait(s.chopstick[i]);//wait(s.chopstick[(i+1)mod(s.n)]);//eat;signal(s.chopstick[i]);signal(s.chopstick[(i+1)mod(s.n)]);think;9}voidprofess(semaphore&s){//ANDthink;Swait(s.chopstick[i],s.chopstick[(i+1)mod(s.n));eat;Ssignal(s.chopstick[i],s.chopstick[(i+1)mod(s.n)]);}-Wmutex,Readercountreadcountvoidinit(semaphore&s){s.rmutex=1;s.wmutex=1;s.readcount=0;}voidreader(semaphore&s){wait(s.rmutex);//if(readcount==0)wait(s.wmutex);//s.readcount++;//signal(s.rmutex);//rmutexread;//wait(s.rmutex);//s.readcount--;if(s.readcount==0)signal(s.wmutex);//signal(s.rmutex);}voidwriter(semaphore&s){wait(s.wmutex);write;signal(s.wmutex);}712:31081.jobstepJCBJCBJCBJCBFCFS112.123CPU123341I/OT=TTsW=T/Ts,12T=2341235FCFSFCFScpuI/OSJ(P)FSJFSPF=+/=/13RRCPUFCFSFCFSnn1-i-1iii61ABBI/OBAAP1:REQUEST(S3);RELEASE(S1);P2:REQUEST(S1);RELEASE(S2);P3:REQUEST(S2);RELEASE(S3);2147-8#defineMAX10/*avaliable[j]=k,RjKMAXnmMAX[i][j]=k,iRjkallocation[i][j]=k,iRjkneed[i][j]=k,iRjkNeed[i][j]=Max[i][j]-Allocation[i][j];*/typedefstructbank{intavaliable[MAX];//intMax[MAX][MAX];//intAllocation[MAX][MAX];//intneed[MAX][MAX];//}bank;request_iPirequest_i[j]=k,PiKRjPi1request_i[j]=need[i][j],22request_i[j]=avaliable[j],33Avaliable[j]=avaliable[j]-request_i[j];Allocation[i][j]=allocation[i][j]+request_i[j];Need[i][j]=need[i][j]-request_i[j];4)15voidallocate(bank&ba,intrequest[][MAX],inti,intj){if(request[i][j]=ba.need[i][j]){if(request[i][j]=ba.avaliable[i][j]){//ba.avaliable[i][j]=ba.avaliable[i][j]-request[i][j];ba.Allocation[i][j]=ba.Allocation[i][j]+request[i][j];ba.need[i][j]=ba.need[i][j]-request[i][j];}}}workwork=availableFinishfinish[i]=false;finish[i]=true;voidcheck(bank&ba,intwork[],boolfinish[],inti,intj){if(finish[i]==false&&ba.need[i][j]=work[j]){//Pi//work[j]=work[j]+ba.Allocation[i][j];finish[i]=true;}else{if(finish[i]==true)//}}1NEG=(N,E)NPRN=PREPRe={pi,Rj}E={Rj,Pi}R1R2P1P2162SPi,PiPiP1P1P2P2P210A,B,CL,M,NACALLBBCALLCA,B,C121700L-1L-1L0M-1L+M-1L+M0N-1L+M+N-11FFFF2NF3BF4WF5QF2kk1=k=m;22mACALLBCBCALLCAJSRLBJSRL+MC182=19020114KB12312^20ALDD=[A]MODL+CPU324KB1232-122010102031023450=+1234,,21512.:,.:.:::,..:1)CPU2)12OS:12Bi=(si/s)*ms=mSi3226123LRU4Clock1010FIFO15clock

1 / 22
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功