I am to use semaphores and threads to do this program. I do not need the actual
ID: 3641247 • Letter: I
Question
I am to use semaphores and threads to do this program. I do not need the actual code. All I need is how to start or what to do because I know that I have to semaphore for number of offices and waiting room but I cannot figure our how to signal the nurse to take the patient or how patients signal doctors. Pseudocode will be very helpful
Overview:
The clinic to be simulated has doctors, each of which has their own nurse. Each doctor has an office of his or her own in which to visit patients. Patients will enter the clinic to see a doctor, which should be randomly assigned. Initially, a patient enters the waiting room and waits to register with the receptionist. Once registered, the patient sits in the waiting room until the nurse calls. The receptionist lets the nurse know a patient is waiting. The nurse directs the patient to the doctor’s office and tells the doctor that a patient is waiting. The doctor visits the patient and listens to the patient’s symptoms. The doctor advises the patient on the action to take. The patient then leaves.
Threads:
Receptionist – one thread
Doctor – one thread each
Nurse – one per doctor thread, identifier of doctor and corresponding nurse should match
Patient – one thread each
Sample Output: With 3 Doctors, Nurses, Patients
Patient 0 enters waiting room, waits for receptionist
Receptionist registers patient 0
Patient 0 leaves receptionist and sits in waiting room
Patient 2 enters waiting room, waits for receptionist
Nurse 0 takes patient 0 to doctor's office
Receptionist registers patient 2
Patient 0 enters doctor 0's office
Patient 2 leaves receptionist and sits in waiting room
Patient 1 enters waiting room, waits for receptionist
Nurse 2 takes patient 2 to doctor's office
Receptionist registers patient 1
Patient 2 enters doctor 2's office
Doctor 0 listens to symptoms from patient 0
Patient 1 leaves receptionist and sits in waiting room
Patient 0 receives advice from doctor 0
Doctor 2 listens to symptoms from patient 2
Patient 2 receives advice from doctor 2
Nurse 1 takes patient 1 to doctor's office
Patient 1 enters doctor 1's office
Doctor 1 listens to symptoms from patient 1
Patient 1 receives advice from doctor 1
Patient 0 leaves
Patient 2 leaves
Patient 1 leaves
Explanation / Answer
Initially, a patient enters the waiting room and waits to register with the receptionist. Once registered, the patient sits in the waiting room until the nurse calls. The receptionist lets the nurse know a patient is waiting. The nurse directs the patient to the doctor’s office and tells the doctor that a patient is waiting. The doctor visits the patient and listens to the patient’s symptoms. The doctor advises the patient on the action to take. The patient then leaves. Initially, a patient enters the waiting room and waits to register with the receptionist. Once registered, the patient sits in the waiting room until the nurse calls. The receptionist adds the application pointer to a queue, along with nurseid. The nurse reads from the queue, one application at a time and processes the application, and add the same application pointer to a queue, along with doctorid. The doctor reads from the queue, one application at a time and treats the patient.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.