You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our solution ensures fairness and mutual exclusion by using semaphores to determine who can enter the costume department. At the start of the program, either the ninjas or pirates have their semaphore set to 2, which means that 2 of them are allowed to enter the costume department. Each ninja and pirate waits on their semaphore to enter the costume department. Once inside, the person increments their counter to let everyone know how many people are currently in the costume department. When someone is about to leave, they check the value of that counter and the value of their semaphore to check if they are both zero. If they are both zero, they up the other people's semaphore twice to allow two people of the other class to enter. This ensures that only 2 people of the same class can enter at the same time and that both groups get equal amounts of time in the costume department.