Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in C++ please: Threads and Semaphores Design the following 2 things (1) a list of every semaphore, its purpose, and its initial value, (2)

Solve in C++ please:

Threads and Semaphores

Design the following 2 things

(1) a list of every semaphore, its purpose, and its initial value,

(2) pseudocode for each function. The pseudocode should be similar to the pseudocode shown in the textbook for the barbershop problem. Every wait and signal call must be included in the pseudocode.

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 doctors office and tells the doctor that a patient is waiting. The doctor visits the patient and listens to the patients symptoms. The doctor advises the patient on the action to take. The patient then leaves. Threads: number of patient and doctors should be command line inputs

Receptionist one thread Doctor one thread each, maximum of 3 doctors Nurse one per doctor thread, identifier of doctor and corresponding nurse should match Patient one thread each, up to 30 patients

Other rules:

A thread should sleep 1 second at each step the thread prints an activity.

All mutual exclusion and coordination must be achieved with semaphores.

A thread may not use sleeping as a means of coordination.

Busy waiting (polling) is not allowed.

Mutual exclusion should be kept to a minimum to allow the most concurrency.

Each thread should only print its own activities. The patient threads prints patient actions and the doctor threads prints doctor actions, etc.

Your output must include the same information and the same set of steps as the sample output.

Output

Each step of each task of each thread should be printed to the screen with identifying numbers so it is clear which threads are involved.

Begin by printing the number of patients, nurses, and doctors in this run.

THREAD ACTIVITY OUTPUT SAMPLE. Your output should contain the same set of steps per thread:

Run with 3 patients, 3 nurses, 3 doctors

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

.

.

.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

More Books

Students also viewed these Databases questions