Question
The summer is over and it is time for Hogwarts students to return to the school. But, because of a traffic jam on the way
The summer is over and it is time for Hogwarts students to return to the school. But, because of a traffic jam on the way to the King's Cross railway station, a number of Hogwarts students will reach the platform "9 and 3 quarters" late and miss the Hogwarts Express. Realizing the situation, the Hogwarts authorities arranged for a number of flying cars to bring these students to Hogwarts. One car can hold exactly four students; it will not leave with more or fewer. It turns out that all these students are either Gryffindor or Slytherin. To guarantee the safety of the passengers, it is not permissible to put one Gryffindor in the car with three Slytherins, or to put one Slytherin with three Gryffindors. Any other combination is safe. So, Hogwarts authorities also provide each Gryffindor student with one spell and each Slytherin student with a different spell. Each student must perform the spell given to her/him in order to get into a car. Use semaphores to write the code for these spells. Try to ensure that your code does not allow deadlocks or starvation.
Step by Step Solution
3.45 Rating (168 Votes )
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