strcpy(p->state,\ strcpy(p->reason,\ while(q)//插入就绪队列
q=q->next;
q=p;
p->next=NULL;
printf(\生产进程唤醒了!\\n\
}
else{ //唤醒b_s2队首进程,消费进程队列 p=b_s2;
b_s2=b_s2->next;//阻塞指针指向下一个阻塞进程 strcpy(p->state,\ strcpy(p->reason,\ while(q->next)//插入就绪队列
q=q->next;
q->next=p; p->next=NULL;
printf(\消费进程唤醒了!\\n\
}
}
void control() //处理器调度程序 { int rd; int num=0;
link p=ready; if(ready==NULL) //若无就绪进程,结束
return;
while(p) //统计就绪进程个数 { num++;
p=p->next;//最终p变为NULL
}
printf(\就绪进程个数为:%d\\n\
time_t t;
srand((unsigned) time(&t)); rd=rand()%num;//随机函数产生随机数 if(rd==1){ p=ready;
ready=ready->next; ready->next=p; p->next=NULL;
strcpy(ready->state,\
strcpy(ready->next->state,\
} else
strcpy(ready->state,\ pc=ready->breakp;
}
void processor(){ //模拟处理器指令执行 if(strcmp(ready->name,\当前进程为生产者 switch(pc)
{
case 0://produce printf(\生产者生产了字符%c\\n\
rec_p[rp1]=str[sp];//添加到生产记录
sp=(sp+1)%len; pc++;
ready->breakp=pc; //保存断点
break;
case 1: //p(s1) pc++; p(1);
break;
case 2: //put buffer[in]=rec_p[rp1]; //放到缓冲区
printf(\字符成功入驻空缓存!\\n\ rp1++;
in=(in+1)%BUF; pc++;
ready->breakp=pc; //保存断点
break;
case 3: //v(s2) pc++;
printf(\释放一个s2信号\\n\ v(2);
break;
case 4://goto01 printf(\生产进程goto 0 操作\\n\ pc=0;
count--; //剩余字符个数减1
printf(\剩余字符count=%d个\\n\
ready->breakp=pc; //保存断点
if(count<=0){ //生产结束
printf(\生产者结束生产!\\n\
strcpy(p1->state,\ strcpy(p1->reason,\ ready->breakp=-1;
ready=ready->next;//在就绪队列中去掉
}
}
else //当前进程为消费者 switch(pc) {
case 0: //p(s2) pc++; p(2);
break;
case 1: //get printf(\消费者取字符!\\n\ temp=buffer[out]; out=(out+1)%BUF; pc++;
ready->breakp=pc; //保存断点
break;
case 2: //v(s1) pc++;
printf(\释放一个s1\\n\ v(1);
break;
case 3: //consume printf(\消费了字符%c\\n\ rec_c[rp2]=temp;//添加到消费记录 rp2++;
con_cnt++;