?{Р pa[i]=i;Р?}Р}Рvoid bornsa()/*将消费者程序装入sa[]中*/Р{Р?for(i=0;i<=3;i++)Р?{Р sa[i]=i;Р?}Р}Рvoid diaodu()/*处理器调度程序*/Р{Р?while((producter.state=='W')||(consumer.state=='W'))Р?{Р x=rand();/*x随机获得一个数*/Р x=x%2;/*对X取于*/Р if(x==0)/*若X等于零,则执行生产者进程,反之执行消费者进程*/Р {Р process=&producter;/*process表示现行进程,将现行进程置为生产者进程*/Р process1=&consumer;Р }Р elseР {Р process=&consumer;Р process1=&producter;Р }Р pc=process->dd;Р i=pc;/*此时把PC的值付给I*/Р if((process->name=='p')&&(process->state=='W'))Р {Р Р j=pa[i];Р pc=i+1;Р switch(j)Р {Р Р case 0: s1=p(s1);process->dd=pc;break;Р case 1: put();process->state='W';process->dd=pc;break;Р case 2: s2=v(s2);process->dd=pc;break;Р case 3: gotol();process->state='W';process->dd=pc;Р }Р }Р else if((process->name=='c')&&(process->state=='W'))/*执行消费者进程且该进程处于就绪状态*/Р {Р process->state='W';