主题:求助:生产者消费者程序
丁梦晗
[专家分:0] 发布于 2005-06-24 19:12:00
[em54]
操作系统要做生产者与消费者的问题!可是不会做,急死我了!请各位大侠帮助!
回复列表 (共4个回复)
沙发
丁梦晗 [专家分:0] 发布于 2005-06-24 20:33:00
[em21]
怎么没人理我?
板凳
jinjin255690 [专家分:0] 发布于 2005-06-25 20:45:00
能否 说的详细一点,用信号集做吗?
3 楼
jinjin255690 [专家分:0] 发布于 2005-06-25 20:46:00
我的qq是149576784,
4 楼
dong456chang [专家分:0] 发布于 2005-06-28 15:28:00
#include<stdio.h>
#include<math.h>
int buffer[4];
int wait[100];
p()
{printf("producer==1.\n");
printf("consumer==2.\n");
printf("exit==0.\n");}
main()
{int a=1,empty=4,full=0,i=0,j=0,t=0,m,b,k=0;
clrscr();
p();
while(a!=0)
{printf("a=");
scanf("%d",&a);
switch(a)
{
case 1:
printf("the producer is ");
scanf("%d",&m);
empty=empty-1;
if(empty<0)
{wait[t]=m;
printf("the buffer is full\n");
{printf("%d is in wait queue\n",wait[t]);}
t=(t+1) % 100;
break;}
d: buffer[i]=m;
i=(i+1) % 4;
full=full+1;
if(full<=0)
goto c;
break;
case 2:
full=full-1;
if(full<0)
{printf("the buffer is empty\n");break;}
else
c: {printf("the consumer is ");
b=buffer[j];
printf("%d\n",b);
j=(j+1) % 4;
empty=empty+1;
if(empty<=0)
{m=wait[k];
k=(k+1) % 100;
goto d;}}
break;
case 0:
break;}}}
这是用c语言编写的
我来回复