【发布时间】:2015-09-26 17:36:30
【问题描述】:
我是操作系统的新手,我没有得到生产者消费者问题的解决方案, 生产者进程被给出为
item nextProduced;
while(true)
{
while(((in+1)%BUFFER_SIZE)==out)
; /* do nothing */
buffer[in]=nextProduced;
in=(in+1)% BUFFER_SIZE;
}
消费者进程由-
给出item nextConsumed;
while(true)
{
while(in==out)
; /* do nothing */
nextConsumed=buffer[out];
out=(out+1)% BUFFER_SIZE;
}
我没有得到的是- 书中写到,在有界缓冲区的情况下,如果缓冲区为空,消费者必须等待,如果缓冲区已满,生产者必须等待, 但从上面给出的过程中, 如果缓冲区已满,则第二个while循环的条件为真,因此该过程将进入无限循环并且不会出来,那么这个解决方案将如何工作。 有人请解释一下,如果您可以举个实际的例子那就太好了!
【问题讨论】:
-
发布
in和out的声明。
标签: c process operating-system infinite-loop