Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on a task very similar to THE SLEEPING BARBER, only in this task it's the sleeping doctor and the cutormers are patients,
I am working on a task very similar to THE SLEEPING BARBER, only in this task it's the sleeping doctor and the cutormers are patients, not there to get their hair done but instead to get tested for covid.
COVID Testing Station There is a drive-through COVID testing station at the end of a dead-end road. People who would like to get tested can drop in unannounced and get a test without even leaving their cars. The doctor who performs the tests can only test one patient at a time. When nobody is waiting to get tested, the doctor takes a break. If a car arrives and sees that no one is being tested, it must notify the doctor that they have arrived. If the doctor is performing a test, any additional arriving vehicles will wait in line. The road leading up to the test station can fit a certain number of cars until the queue blocks the previous intersection. Therefore, if a vehicle arrives and sees that the line is full, they will take a detour and try again later. Using POSIX threads, mutex locks, and semaphores, implement a solution that coordinates the activities of the doctor and the cars. Implementation details Using Pthreads, begin by creating n cars where each car will run as a separate thread. The doctor will run as a separate thread as well. Every car should alternate between driving around and trying to get tested. If the doctor is available, they will get tested. Otherwise, they will either wait in line or take a detour and come back later if the line was full. If a car arrives and finds the doctor taking a break, the car must notify the doctor using a semaphore. When the doctor finishes a test, the doctor must check to see if any cars are waiting. If so, the doctor continues by testing the patient in the next car in line. If no one is waiting, the doctor goes back to taking a break. Perhaps the best option for simulating cars taking detours and the doctor performing tests is to have the appropriate threads sleep for a random period of time. See the following example on how to use the rand function in C to achieve thisStep 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