Question
Operating System: The local Laundromat has just entered the computer age. As each customer enters, he or she puts coins into slot at one of
Operating System:
The local Laundromat has just entered the computer age. As each customer enters, he or she puts coins into slot at one of two stations and type 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 a Boolean array available[NMACHINES] to represent if corresponding machines are available (NMACHINES is a constant indicating how many machines there are in the Laundromat), and a semaphore nfree that indicates how many machines are available. The code to allocate and release machines is as follows.
The available array is initialized to all true, and nfree is initialized to NMACHINES.
int allocate () /*Returns index of available machine */ { wait(nfree); /*Wait until a machine is available */ for hint i=0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started