《操作系统第2章进程管理-习题.ppt》由会员分享,可在线阅读,更多相关《操作系统第2章进程管理-习题.ppt(8页珍藏版)》请在三一办公上搜索。
1、2.试画出下面四条语句的前趋图:S1:a:=x+y S2:b:=z+1 S3:c:=a-b S4:w:=c+1,图 2-2题 四条语句的前趋关系,26.试修改下面生产者消费者问题解法中的错误:,Var mutex,empty,full:semaphore:=1,n,0;buffer:array0,n-1 of item;in,out:integer:=0,0;begin parbegin producer:begin repeat producer an item nextp;wait(mutex);wait(empty);wait(full);wait(mutex);buffer(in):=
2、nextp;in:=in+1 mod n;signal(mutex);signal(full);until false;end,consumer:begin repeat wait(mutex);wait(full);wait(empty);wait(mutex);nextc:=buffer(out);out:=(out+1);out:=(out+1)mod n;signal(mutex);signal(empty);consumer the item in nextc;until false;end parend end,Var mutex,empty,full:semaphore:=1,n
3、,0;buffer:array0,n-1 of item;in,out:integer:=0,0;begin parbegin producer:begin repeat producer an item nextp;wait(empty);wait(mutex);buffer(in):=nextp;in:=(in+1)mod n;signal(mutex);signal(full);until false;end,consumer:begin repeat wait(full);wait(mutex);nextc:=buffer(out);out:=(out+1)mod n;signal(mutex);signal(empty);consumer the item in nextc;until false;end parend end,27 哲学家进餐问题,1.Var chopstick:array0,4 of semaphore;,