Question: 4. Answer both parts: (a) (4 points) Harry Potter and Ron Weasley share the same invisibility cloak. The person inside the invisibility cloak becomes invisible

4. Answer both parts: (a) (4 points) Harry Potter and Ron Weasley share the same invisibility cloak. The person inside the invisibility cloak becomes invisible to others. Whenever Harry or Ron need the cloak, they simply invoke a spell that causes the cloak to come flying to them from wherever it was at that moment. This has some times led to the embarrasing situation where the cloak simply flew off Ron when he was using it because of Harry invoking the spell to fetch it. In other words, the spell would cause the cloak to fly to the invoker even if it is currently in use. How would you fix the spell so that it waits for the cloak's current use to be over before making the cloak come to the invoker? Provide the pseudo-code for the spell. (Hint: you may use a semaphore.) (b) (6 points) The faculty at Hogwarts come to the room with an infinite supply of pasta whenever they get hungry. The room has a round table with 'n' chairs, 'n' plates and 'n' forks (where 'n' is the number of Hogwarts faculty members). There is a plate and a fork in front of each chair. Whenever a professor sits on the chair, she grabs the fork lying in front and then the fork lying in front of the chair to the left and starts to eat. After finishing the food, she washes the forks/plate and puts them back in their places. Each professor follows the same protocol every time he/she eats food (pick the fork in front and then the fork on the left, eat, replace the forks to their original spots). If she does not find a particular fork at its place (because some one else is using it), she waits for the fork to become available. This has led to unfortunate situations where all 'n' professors are sitting around the table holding on to one fork each and waiting forever for the other fork to become available (which of course will never happen). In other words, this scenario has a clear potential for a deadlock to happen. Knowing what you know about the necessary and sufficient conditions for a deadlock, suggest two different solutions that will prevent a deadlock from happening in this situation and allow all professors to eat their pasta in a finite amount of time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
