Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Wash - O - Matic Laundromat is a computerized laundry reservation system. As each customer enters, he or she puts coins into slots at
The WashOMatic Laundromat is a computerized laundry reservation system. As each customer enters, he or she puts coins into slots at one of two stations and types in the number of washing machines heshe 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 availableNMACHINES whose elements are nonzero if the corresponding machine is available; NMACHINES is a constant equal to the number of machines there are in the Laundromat, and nfree is a semaphore that indicates the number of available machines.
The code to allocate and release machines is as follows:
synch
The available array is initialized to all ones, and semaphore nfree is initialized to NMACHINES. It seems that if two people make requests at the two stations at the same time, they will occasionally be assigned the same machine. This has resulted in several brawls in the Laundromat, and you have been called in by the owner to fix the problem. Assume that one process handles each customer station.
What modification in the code can resolve the issue of multiple customers being assigned the same machine?
a
Implement a lock at the beginning of the allocate function to prevent simultaneous access.
b
Add a semaphore check before returning the index of an available machine.
c
Use a loop in the release function to ensure all related variables are properly reset.
d
Implement a mutex to ensure only one station can access the available machines array at a time.
Step 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