全文预览

p、v原语的模拟实现

上传者:读书之乐 |  格式:doc  |  页数:8 |  大小:65KB

文档介绍
a')gotoa1;if(addr=='b')gotob1;if(addr=='c')gotoc1;for(i=1;i<6;++i){?printf("process1,callsPonsemaphore2\n");?if(p(1,'a'))break;///*process1isbiocked*/a1:printf("utingonitscreticalsection\n");?if(timeint('b'))break;b1:printf("s2=%d\n",++s2);printf("process1callsVonsemapore2andquitcreticalsection\n");?if(v(1,'c'))break;//*wakeupabiockedprocess*/c1:printf("process1cyciencount=%d\n",i);}if(i<6)return;?eexit(2);}main(){?intk;?printf("****processmanagement****\n\n");?init();?printf("s1=%d,s2=%d\n",s1,s2);?printf("process1,process2,process1areallinready!\n");?for(;;) if((k=scheduler())!=NIL) switch(k) { case0:process1(); break; case1:process2(); break; case2:process1(); break; default:printf("processidentifererror\n"); break; } elsebreak; printf("s1=%d,s2=%d\n",s1,s2); printf("\n****END****\n");}

收藏

分享

举报
下载此文档