Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. (10 points) This question is about the use of semaphores to implement concurrency control related constraints. Because of COVID-19, the EMS building cannot have
4. (10 points) This question is about the use of semaphores to implement concurrency control related constraints. Because of COVID-19, the EMS building cannot have more than x people inside at any given time, where x is a configurable constant. The EMS building has exactly y doors that stay closed by default and allow only one person to enter/leave at a time. In order to enter the building, a person must press the enter button on one of the doors, which causes the door to execute an enter Request() method that returns true or false. If the number of people currently inside the building is less than x, enter Request() increments that number by one and returns true; otherwise it returns false. If the enterRequest() method returns true, the door opens and admits exactly one person. In order to leave the building, a person must press the leave button on one of the doors, which causes the door to execute a leaveRequest() method that decrements the number of people currently inside the building by one and returns true. If the leaveRequest() method returns true, the door opens and lets exactly one person leave the building Write the code for enter Request() and leaveRequest() methods that will work correctly when executed by any of the doors in the building. You can assume that only a real person can press the enter/exit buttons. 4. (10 points) This question is about the use of semaphores to implement concurrency control related constraints. Because of COVID-19, the EMS building cannot have more than x people inside at any given time, where x is a configurable constant. The EMS building has exactly y doors that stay closed by default and allow only one person to enter/leave at a time. In order to enter the building, a person must press the enter button on one of the doors, which causes the door to execute an enter Request() method that returns true or false. If the number of people currently inside the building is less than x, enter Request() increments that number by one and returns true; otherwise it returns false. If the enterRequest() method returns true, the door opens and admits exactly one person. In order to leave the building, a person must press the leave button on one of the doors, which causes the door to execute a leaveRequest() method that decrements the number of people currently inside the building by one and returns true. If the leaveRequest() method returns true, the door opens and lets exactly one person leave the building Write the code for enter Request() and leaveRequest() methods that will work correctly when executed by any of the doors in the building. You can assume that only a real person can press the enter/exit buttons
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