Multithread Application:.

Added on - 16 Sep 2019

  • 2


  • 606


  • 151


  • 0


Showing pages 1 to 1 of 2 pages
Multithread Application:Consider a pizza cafe where there are only N seats. When a customer enters the store, (s)he buysa pizza and grabs a seat to eat. When the customer finishes eating, (s)he leaves the store. If thereis any unsold pizza left, (s)he can get it immediately. Otherwise, (s)he need wait for the chef tomake one. A chef in the kitchen just keeps making pizzas until there are M unsold pizzas left inthe kitchen. (S)he resumes the work when a customer comes to buy one.After the customer gets the pizza, (s)he tries to find a seat. If there is any available seat, (s)hegrabs the seat and eats the pizza. Otherwise, (s)he waits until another customer finishes eatingand leaves the café..You are asked to simulate this problem as following:1.Your program should first ask user to input M (the number of plates to hold unsold pizza) andN (the number of seats). You can also pass these two numbers through command lineparameters. The maximum number should be 10 for both parameters. (10%)2.You need create two types of threads besides the main thread: chef and customer. There isonly one chef thread but multiple customer threads. The number of customers should berandomly generated. Assuming the maximum number is 20. (For example, you can userandom()/srandom() or drand48()/srand48() to generate a random number in C) (10%)3.Suppose each customer only buys one pizza. Their eating time is randomized between 1 to 10time units. Assume it takes the chef 5 time units to make a pizza and the chef only makesenough pizzas for all customers. Implement the chef and the customer threads. The programshould stop when all customers finish eating their pizzas, and no pizza should be left in thekitchen at the end. (You can define a time unit by yourself, e.g. a second, or a microsecond,or a fixed number of loops) (30%)4.Synchronize the chef and customers so that at any time, there are no more than M unsoldpizza and no more than N customers sitting and eating the pizza. (50%)5.You can choose any programming language (e.g. C/C++/Java/python) to implement thisprogram. You can find some sample C and Java code on the blackboard.6.Your output may look like the following:Please input M: 5Please input N: 8The total number of customers is 17Create a chef threadCreate 17 customer threadsCustomer 1 arrivesChef makes pizza 1. 1 pizza unsoldChef makes pizza 2. 2 pizzas unsold.Customer 1 buys a pizza. 1 pizza unsold.Customer 2 arrivesCustomer 2 buys a pizza, 0 pizza unsold.Customer1 gets a seat, 7 seats left.Chef makes pizza 3. 1 pizza unsold.Customer 1 finishes eating and leaves. 8 seats left.Chef makes pizza 4. 2 pizzas unsold.Customer 3 arrives
You’re reading a preview

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document