if( i==10)
{
i=0;//when i is producer1_message[i]
produer1_message[0]="producer1--1 ";;//as when the second loop ,show a unaccept info
PC_DispStr(15,12," ",font_color);
}
void producer1(void *pdata)
{
char *produer1_message[10]={
"producer1--1 ", "producer1--2",
"producer1--3", "producer1--4",
"producer1--5", "producer1--6",
"producer1--7", "producer1--8",
"producer1--9", "producer1--10",
};
INT8U i=0;//product tag
INT8U err;// save OSQPost() return infomation
char delete_info[5];
char display_info[20];
pdata=pdata;
for(;;)
{
if( i==10)
{
i=0;//when i is producer1_message[i]
produer1_message[0]="producer1--1 ";//as when the second loop ,show a unaccept info
PC_DispStr(15,12," ",font_color);
}
sprintf(delete_info,"%d",i);
PC_DispStr(15,21,delete_info,font_color);
PC_DispStr(15,22,produer1_message[i],font_color);
err=OSQPost(q_buf,(void *)produer1_message[i]);
switch(err)
{//test err
case OS_NO_ERR:
{
sprintf( display_info,"producer1--%d success",i+1);
PC_DispStr(15,12,display_info,font_color);
break;
}
case OS_Q_FULL:
{
PC_DispStr(15,12,"the buffer is full, don't add",font_color);
break;
}
default :break;
}
i++;
OSTimeDly(400);
}
}
|
1控制各任务等待的时间,可决定消费者,与生成者的关系。
producer1:OSTimeDly(100);
producer2:OSTimeDly(100);
consumer1:OSTimeDly(200);
consumer2:OSTimeDly(200);
这样生产者就使消息队列满了,
2
覆盖当10出现后,再出1 时,后面还有0,定义消息队列时,小于10的每个后面加一空格。
char *produer1_message[10]={
"producer1--1 ", "producer1--2 ",
"producer1--3 ", "producer1--4 ",
"producer1--5 ", "producer1--6 ",
"producer1--7 ", "producer1--8 ",
"producer1--9 ", "producer1--10",
};
3
不知为什么,当消息队列第一次満后,再从头添加消
阅读(1337) | 评论(0) | 转发(0) |