The summer is over and it is time for Hogwarts students to return to the school. But,
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 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.
Statistics for the Life Sciences
ISBN: 978-0321989581
5th edition
Authors: Myra Samuels, Jeffrey Witmer, Andrew Schaffner