第一题:
(1)、典型事件:
①、就绪->运行:cpu空闲,就绪状态被选中
②、运行->就绪:正在运行的进程本次分配的cpu时间片
③、运行->阻塞:运行态进程因某种条件未满足而放弃对cpu的占用
④、阻塞->就绪:阻塞态进程所等待的事件发生了
(2)、因果转换:
③->①:运行->阻塞->就绪
③->②:运行->阻塞->就绪
②->①:运行->就绪->运行
④->①:阻塞->就绪->执行
第二题:
begian
parbegin
begin P1:V(a),V(b),V©,end
begin P(a):P2,V(d),end
begin P(b):P3,V(e),end
begin P©:P4,V(f),end
begin P(d)😛(e),p(f),p6,end
parend
end
第三题:
Int mutex=1,empty=1,full=0,apple=0,orange=0;
Void Father( int mutex,empty,apple)
{ While(条件真)
{ P(empty);
P(mutex);
放苹果;
V(mutex);
P(orange);
}
}
Void Mother( int mutex,empty,orange )
{ While(条件真)
{ P(empty);
P(mutex);
放橘子;
V(mutex);
P(full2) ;
}
}
Void Son( int apple,mutex,empty )
{ While(条件真)
{ P(apple) ;
P(mutex);
取苹果;
V(mutex);
P(empty) ;
吃苹果;
}
}
void Daughter( int orange,mutex,empty)
{ While(条件真)
{ P(orange);
P(mutex);
取橘子;
V(mutex)
P(empty)
}
}
main( )
{ cobegin
Father;
Mother;
San;
Daught;
}