Question
Multithreaded synchronisation, pseudocode Consider a multithreaded program that simulates a dentists surgery. The surgery has a single room with N chairs for waiting patients and
Multithreaded synchronisation, pseudocode Consider a multithreaded program that simulates a dentists surgery. The surgery has a single room with N chairs for waiting patients and the dentists treatment chair in which the patient currently treated sits. The program uses semaphores for thread synchronisation. When there are no patients the dentists sleeps. When the patient arrives while a patient is being treated, they sit in one of N chairs...( check photo) This part of the question requires you to write pseudo code for the Room member functions listed. These should provide thread synchronisation using semaphores. The semaphores must all be private data members of the room class. i)How many semaphores does the Room class need and what are their purpose? ii)Define the initial value for each semaphore, justifying your choice. iii)Write the pseudo code for each member function
Consider a multi-threaded program that simulates a dentist's surgery. The surgery has a single room with N chairs for waiting patients, and the dentist's treatment chair in which the patient currently being treated sits. The program uses semaphores for thread synchronisation. When there are no patients, the dentist sleeps. When a patient arrives, the dentist awakes and the patient is treated. If additional patients arrive while a patient is being treated, they sit in one of the N chairs whilst waiting for treatment. If there are no free waiting chairs, patients are forced to wait outside the surgery room. Under these circumstances, a patient that leaves the room enables a patient who is waiting outside the room to be admitted. The dentist and patients are modelled by threads. An object of class Room provides most of the necessary thread synchronisation and is the focus of this question. Its public member functions are defined in Figure Q1.1. Chairs are not represented explicitly in the program. Member function void entry(); Purpose Allows patient threads to enter the room if there are less than N+1 patient threads currently present Records that a patient thread has left the room Called by Patient threads void exit(); Patient threads Dentist thread void isPatientAvailable(); Checks if there are any patient threads awaiting treatment void patientWaiting(); Called to indicate that a patient has arrived in the surgery room and is awaiting treatment void dentistFree(); Called to indicate the dentist has finished the treatment of a patient Figure Q1.1. Patient thread Dentist thread In answering this question, you can assume that the patient and dentist threads each have a pointer to the same Room object. Consider a multi-threaded program that simulates a dentist's surgery. The surgery has a single room with N chairs for waiting patients, and the dentist's treatment chair in which the patient currently being treated sits. The program uses semaphores for thread synchronisation. When there are no patients, the dentist sleeps. When a patient arrives, the dentist awakes and the patient is treated. If additional patients arrive while a patient is being treated, they sit in one of the N chairs whilst waiting for treatment. If there are no free waiting chairs, patients are forced to wait outside the surgery room. Under these circumstances, a patient that leaves the room enables a patient who is waiting outside the room to be admitted. The dentist and patients are modelled by threads. An object of class Room provides most of the necessary thread synchronisation and is the focus of this question. Its public member functions are defined in Figure Q1.1. Chairs are not represented explicitly in the program. Member function void entry(); Purpose Allows patient threads to enter the room if there are less than N+1 patient threads currently present Records that a patient thread has left the room Called by Patient threads void exit(); Patient threads Dentist thread void isPatientAvailable(); Checks if there are any patient threads awaiting treatment void patientWaiting(); Called to indicate that a patient has arrived in the surgery room and is awaiting treatment void dentistFree(); Called to indicate the dentist has finished the treatment of a patient Figure Q1.1. Patient thread Dentist thread In answering this question, you can assume that the patient and dentist threads each have a pointer to the same Room objectStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started