Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The project must be written in C, C++, or Java. If using C or C++, you must use POSIX pthreads and semaphores. If using Java,

The project must be written in C, C++, or Java. If using C or C++, you must use POSIX pthreads and semaphores. If using Java, you must use Java Threads and Java Semaphores (java.util.concurrent.Semaphore). You should not use the synchronized keyword in Java. You should not use any Java classes that have built-in mutual exclusion. Any mechanisms for thread coordination other than the semaphore are not allowed.

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

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

Inputs

The program should receive the number of doctors and patients as command-line inputs.

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

Students also viewed these Databases questions