Question: In this problem, we write code to simulate a producer and consumer problem using multiple threads. To make the problem easier to understand, we use

In this problem, we write code to simulate a producer and consumer problem using multiple threads. To make the problem easier to understand, we use a fast food restaurant analogy. Assume we have a fast food restaurant serving only one type of drink, one type of fries, and one type of burger. Customers order their food online and each customer can only order one drink, one fries and one burger. Since there are only type of drink, one type of fries and one type of burger, all orders are identical. Each of the these three items will be put into a queue implemented by a linked-list, which is accessed by the restaurant employees. Each employee will remove one item from the front of the linked-list and prepare the item, and put the prepared item into a sliding tray so that the item will slide down to the bottom for customers to pick up. The sliding tray has 3 columns, one for drinks, one for fries and one for burgers. A customer will pick up the food if all the 3 columns have items at the bottom of the tray. Since all the orders are identical, any customer can pick a order when it is available. Moreover, the sliding tray can hold limited number of items in each of the column. Because of this limitation, an employee needs to wait before he can put an item in the tray if the column for that item is full.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!