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 linkedlist, which is accessed by the restaurant employees. Each employee will remove one item from the front of the linkedlist 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 columns, one for drinks, one for fries and one for burgers. A customer will pick up the food if all the 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
