CSE344 Homework 4- v3 Fun with threads and semaphores Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

 

Let’s assume for the sake of simplicity that one needs exactly 4 ingredients for preparing güllaç: – milk (M)

  • flour (F)
  • walnuts (W) – sugar (S).

There are 6 chefs in a street, and each has an endless supply of two distinct ingredients and lacks the remaining two:

e.g.

chef1 has an endless supply of milk and flour but lacks walnuts and sugar, chef2 has an endless supply of milk and sugar but lacks flour and walnuts, chef3 has an endless supply of milk and walnuts but lacks sugar and flour, etc.

Every chef sits in front of her/his store and waits for the remaining two ingredients to arrive in order to go and prepare güllaç.

There is also a wholesaler that every once in a while delivers two distinct ingredients out of the four to the street of the chefs, lets the chefs know that the ingredients have arrived and then waits for the dessert to be ready. Once the güllaç is ready, the wholesaler must take it for sale and the
chefs must wait again for the next visit of the wholesaler.  

Your objective is to implement the chefs and the wholesaler as 6+1 threads that print on screen their activities. If your program is successful it could for instance print something like the following:

… chef2 is waiting for flour and walnuts chef3 is waiting for sugar and flour chef1 is waiting for walnuts and sugar

… the wholesaler delivers sugar and flour

chef3 has taken the sugar

the wholesaler is waiting for the dessert

chef3 has taken the flour chef3 is preparing the dessert

chef3 has delivered the dessert to the wholesaler the wholesaler has obtained the dessert and left to sell it

chef3 is waiting for sugar and flour …

The wholesaler will read the ingredients to deliver from a file containing two letters at each line, representing the ingredients to deliver; e.g.

MS

FM WS

etc

Assume the file has valid content and at least 10 rows. The wholesaler will be represented by the main thread, and will join all the threads of the chefs before terminating.

./program -i filePath

The ingredients will be delivered to a data structure of your choosing (e.g. array, stack, etc), located at the heap and thus shared among all involved threads. Be care

  • HW04-87bz94.zip