homework 4 Version 0 |
|
👤 Author: by 491975124qqcom 2019-10-09 12:52:36 |
Case: There is a dish on the table,every time can just put an apple or an orange in the dish.Dad put apples into the dish,mom put oranges into the dish. The son only eat orange and the daughter only eat apple.Only when the dish is empty,dad and mom will put fruit into the dish,and only when there is the fruit they want in the dish ,they will pick one.
Solution:
int e=1,a=o=0;
main(){
father(); //daughter (); //son();
}
father(){
while(1){
wash fruit;
wait(e);
put fruit into the dish;
if(fruit=apple) signal(a);
else signal(o);}
}
son(){
while(1){
wait(o)
pick an orange from the dish;
signal(e);
eat an orange;}
}
daughter(){
while(1){
wait(a)
pick an apple from the dish;
signal(e);
eat an apple;}
}