This was a project for the Operating systems with concurrency programming course.
The museum has 2 halls - A and B with limited capacity and CA > CB. Some of the visitors want to go to the A hall and leave, others want to visit both exhibitions. This environment was used to formulate two problems:
- Maximize the number of visitors who visit the museum at the same time.
- Allow people from hall B to leave the museum as fast as possible.
My take on the first problem was to allow the visitors to fill hall B while always leaving one spot free in hall A. This solution prevents deadlock that could occur when the visitors are trying to fill the full hall B while maximizing the number of visitors who visit the museum simultaneously. The implementation of this solution is based on the following idea:
- Counting semaphores sem.A and sem.B initialized with respectively CA-1 and CB are used to control the number of visitors who can enter the specific hall.
- A mutex mutex.B is used to allow only one visitor to leave hall B at a time.
For the second problem, the solution is to reserve empty spots in hall A to allow the visitors to leave hall B as fast as possible. I implemented this solution by using two semaphores sem.A and sem.B initialized with respectively CA and CB.