生产者消费者问题的 FIFO 队列不工作
我目前正在尝试实现 FIFO 来解决生产者消费者问题。然而,当我运行代码时,似乎第一个项目没有从缓冲区中删除,因为输出显示每个消费者都在消耗第一个项目,而不是其他项目(附加输出的屏幕截图)。
我实现了一个 LIFO 队列并得到了预期的结果,这让我相信问题出在我的 FIFO 实现上。
I currently am trying to implement FIFO for the producer consumer problem. However when I run the code it seems that the first item is not being removed from the buffer as the output shows that every consumer is consuming the first item and never the others (Screenshot of output attached).
I implemented a LIFO queue and got the expected result which is what leads me to believe that the issue is with my FIFO implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出队时出现简单错误。想象一下您想要获取队列中的第一个条目(buffer_rd == 0)。但是你增加 buffer_rd 和读取 theat 条目,
你需要反转这 2 个(就像在插入中一样)
Simple error in dequeue. Imagine you want to get the first entry in the queue ( buffer_rd == 0). But you increment buffer_rd and the read theat entry,
you need to reverse those 2 (like in insert)