[SOLVED] CSE344 Homework 3-Semaphores

30.00 $

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

You will receive the following solution file(s) instantly after successful payment:

zip file icon hw3-imct0w.zip (483.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

Semaphores

You will prepare a small bakers simulation inspired by a classic synchronization problem. Let’s assume for the sake of simplicity that one needs exactly 4 ingredients for preparing güllaç:
– milk (M)
– flour (F)

– walnuts (W)
– and sugar (S).

6 x Chef

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

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

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ç. Once the güllaç is ready they deliver it to the wholesaler and continue to wait for more ingredients. In case of termination, each chef process will return (and by “return” I actually mean return, not print on screen) the total number of desserts it has prepared so far.

1 x Wholesaler

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.

to

Once the güllaç is ready, the wholesaler takes it for sale and the chefs must wait again for the next visit of the wholesaler.

The wholesaler will read the ingredients to deliver from an input file containing two capital letters at each line, representing the ingredients to deliver; e.g.
MS
FM

WS SM etc

Assume the file has valid content and at least 1 row. The ingredients will be stored in a character array taking place in a shared memory segment; if the wholesaler for instance delivers SM, the array will contain ‘S’ and ‘M’. After the wholesaler is done (i.e. he has no more ingredients to

April 20th, 2022

However, do not assume that

the wholesaler knows which chef needs which ingredients

. So do

not make the mistake of signaling

directly from the wholesaler only the chef corresponding

the delivered ingredients. Example: if the wholesaler delivers F and M, don’t just signal/sem_post

the chef waiting for F and M.

deliver, he must notify the chefs that the procedure is over – how? That’s up tp you.) It will collect the return values of the chef processes, and print the total number of desserts delivered to him.

How

You will implement the program as the chefs and the wholesaler in the form of 6+1 processes that print on screen their activities. You will implement two version of the program, one solving it with named semaphores and another solving it with unnamed semaphores.

                    ./hw3named -i inputFilePath -n name
                        ./hw3unnamed -i inputFilePath

-i: denotes the input file path (absolute or relative)
hw3named: must use named semaphores for synchronization (you can include additional args if necessary).
hw3unnamed: must use unnamed semaphores for synchronization.

Output

Chefs (print the contents of the character array containing the ingredients at the end of every output line):

Initially (replace the bold parts; e.g. i becomes the chef id, ingredient becomes Milk, etc): chefi (pid XYZ) is waiting for ingredient1 and ingredient2

After obtaining the ingredients (replace the bold parts): chefi (pid XYZ) has taken the ingredient1 chefi (pid XYZ) has taken the ingredient2 chefi (pid XYZ) is preparing the dessert chefi (pid XYZ) has delivered the dessert

At exit (replace the bold parts): chefi (pid XYZ) is exiting

The wholesaler (replace the bold parts):
the wholesaler (pid XYZ) delivers ingredient1 and ingredient2 the wholesaler (pid XYZ) is waiting for the dessert
the wholesaler (pid XYZ) has obtained the dessert and left the wholesaler (pid XYZ) is done (total desserts: 34)

Evaluation rules

1) Compilation error: grade set to 1; if the error is resolved during the demo, then evaluation continues.
2) Compilation warning (with respect to the -Wall flag); -1 for every warning until 10. -20 points if there are more than 10 warnings; no chance of correction at demo.
3) No makefile: -30
4) No pdf report submitted (or submitted but insufficient, e.g. 3 lines of text with no design explanation, etc): -20. Other file formats are not admissible.
5) If the required command line arguments are missing/invalid, your program must print usage information and exit. Otherwise: -10

6) The program crashes or doesn’t produce the expected output with valid input: -50 for each of the two versions.
7) The program doesn’t satisfy a requirement: -100
8) Presence of memory leak (regardless of amount – checked with valgrind) -30

9) Late submissions will not be accepted
10) In case of an arbitrary error, exit by printing to stderr a nicely formatted informative message. Otherwise: -10
11) Cleanup after the children processes, no zombie processes, -50 otherwise.

Is my homework submission valid?

It is valid if given a correct input file, it creates all necessary processes.

  • hw3-imct0w.zip