Answered step by step
Verified Expert Solution
Question
1 Approved Answer
needs asap (15 points) The local Laundromat has just entered the computer age. As each customer enters, he or she puts coins into slot at
needs asap
(15 points) 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 avai lable [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 avai lable array is initialized to all true, and nfree is initialized to NMACHINES. (a) 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 thread handles each customer station. Explain how the same washing machine can be assigned to two different customers. (b) Modify the code to eliminate the problem, using semaphore onlyStep 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