Now that I have some free time on hand, I felt this would be a good opportunity to do a quick summary of the coursework project’s I undertook at University this past semester.
Architectures and Operating Systems
The main coursework project in this module consisted of understanding a core fundamental of concurrent programming called mutual exclusion. “For this assignment you will create a Java command line program that simulates the behaviour of a meeting of a fictional secret society. A detailed list of the requirements and a description of the expected behaviour is given in the problem statement.”
There are two types of members of this “fictional secret society”, these are referred to as ‘Elders’ and ‘Juniors’. They abide by the rules that follow:
- Each member must enter the vestibule and pay respect to the ‘Senior Elder’.
- If the vestibule is empty, a member of any rank may enter.
- If the vestibule is occupied by members of one rank, members of the other may not enter until the vestibule is empty.
- If an Elder wishes to enter the vestibule, no ‘Junior’ may enter ahead of them. An Elder will wait until all ‘Juniors’ currently in the vestibule have left, then immediately enter. All waiting ‘Juniors’ will enter only once all waiting Elder(s) have occupied and left the vestibule.
- The vestibule has a maximum capacity. Once this is reached, members of either rank must wait until a space becomes available.
- Members need not enter in order of arrival.
We had to simulate this ‘Society’ using the ‘Thread’ class and a ‘Semaphore’ class given to us. I’m aware that this can be done much easier using ‘synchronized’ in Java but the point of this exercise was to understand the underlying principles.
Source Code:
Society.java
Elder.java
Junior.java
Member.java
Semaphore.java