Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Answer for this question!!! Thank you so much. This is the concurrent progr

ID: 3595690 • Letter: N

Question

Need Answer for this question!!! Thank you so much. This is the concurrent programming question. Please obey the rules. I really need learn this to pass my midterm. Thank you

The local laundromat has just entered the computer age. As each customer enters, he or she puts coins into slots at one of two stations and types in the number of washing machines he/she will need. The stations are connected to a central computer that automatically assigns available machines and outputs tokens that identify the machines to be used. The customer puts laundry into the machines and inserts each token into the machine indicated on the token. When a machine finishes its cycle, it informs the computer that it is available again. The computer maintains An array available[NMACHINES] whose elements are non-zero if the corresponding machines are available (NMACHINES is a constant indicating how many machines are there in the laundromat) Using semaphores, write the code to allocate and release the machines. Assume that the available array is initialized to all ones. You are free to use as man solution. Please specify the initial values of the semaphores and/or any global variables used in your solution. y semaphores and other variables as needed for your /* Specify initial values below */ int allocate0 /* returns index of available machine */ release(int machine) /* releases machine */

Explanation / Answer

Ans: Here we we will use a binary semaphore called mutex and a semaphore nFreeMachines to indicate the number of free machines at any point of time. We are using an array available[NMachines] to indicate what all machines are available at any time. available array will be initialized to all ones. binary_sem mutex=1; // binary semaphore initialized to 1. semaphore nFreeMachines = NMACHINES; // nFreeMachines semaphore initialized to NMACHINES int allocate() // Returns index of available machine. { wait(nFreeMachines); // Wait until a machine is available. for (int i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote