苹果-桔子问题的实现 下载本文

{

mother_lag=1; //mother处于等待状态 print(); if(father_lag==0) mf=2;

} else{

mother(); // print();

if(son_lag==1) //等待取消

{

son_lag=0;

printf(\处于等待的son自动被调用。\\n\ son(); }

printf(\━━━━━━━━━━━━━━━━━━━━\\n\ break;

}

case 2:

printf(\调用.\\n\

if(orange==0) {

son_lag=1; //son处于等待状态 print(); } else{

son();

if(mother_lag==1&&father_lag==1) {

24

if(mf==1)

{

father_lag=0;

printf(\处于等待的father自动被调用\\n\ father(); mf=2; } else{

mother_lag=0;

printf(\处于等待的mother自动被调用\\n\ mother(); mf=1; }

} else {

if(mother_lag==1)

{

mother_lag=0;

printf(\处于等待的mother自动被调用\\n\ mother();

mf=0;

}

else if(father_lag==1)

{

father_lag=0;

printf(\处于等待的father自动被调用\\n\ father(); mf=0; }

25

}

}

printf(\━━━━━━━━━━━━━━━━━━━━\\n\

break;

case 3:

printf(\调用\\n\ if(apple==0) {

daughter_lag=1; print(); } else{

daughter();

//print();

if(mother_lag==1&&father_lag==1) {

if(mf==1)

{

father_lag=0;

printf(\处于等待的father自动被调用\\n\ father(); mf=2; } else{

mother_lag=0;

printf(\处于等待的mother自动被调用\\n\ mother(); mf=1; }

26

} else {

if(mother_lag==1)

{

mother_lag=0;

printf(\处于等待的mother自动被调用\\n\ mother();

mf=0;

}

else if(father_lag==1)

{

father_lag=0;

printf(\处于等待的father自动被调用\\n\ father(); mf=0; }

}

}

printf(\━━━━━━━━━━━━━━━━━━━━\\n\

break; } } }

27