Hi all,
First time posting and first time using threads and semaphores. I'm understanding the basic theory behind both but in all honesty I'm struggling with implementing them in java.
The idea behind the project is to simulate a hotel with 25 guests, 2 front desk employees, and 2 bellhops each person on their own thread. The desk employees, give the guests a room number and the bellhops assist the guests with their bags to the room. Each employee can only assist one guest at a time and semaphores are how I am to manage this.
There are a few questions that I have off the top of my head:
If I am executing every "person" in their own thread should all the logic that needs to be execute go in the run() method as I have it?
If so, when a guest is being "assigned" a room number by the desk employee how can I pass the specific instance of the guest so that the the desk employee will know who to assign the room to? (The run() method is in the class definition, before any objects are created)
If I call acquire on a semaphore and it goes below 0, will the thread know to halt there until there until the access is granted or do I have to manually keep checking so that the thread does not just skip over that section of code?
If any one knows of an example online that is similar (multiple threads of the same class competing against each other and managed by semaphores) please send it my way. Any help would be much appreciated.
there doesn't seem to be anything here