Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1C. Use the space below to complete the code for the customer threads. Recall: When a customer arrives, he checks the barber status. If the

1C. Use the space below to complete the code for the customer threads. Recall:

When a customer arrives, he checks the barber status. If the barbers sleeping, the customer wakes the barber up. Otherwise, the customer enters the waiting room.

If a seat is available, the customer takes it; otherwise, he leaves (without waiting)

There may be multiple barbers and customers, with up to N customers waiting in the waiting room. The solution requires three semaphores and a shared variable to track free seats in the waiting room, initialized as shown below. Assume semaphore is a valid type.

semaphore barbers=0; // # free barbers

semaphore customers=0; // #waiting customers

semaphore mutex=1; // used if mutual exclusion needed

int freeSeats=N; // # free seats in waiting room

You may write pseudo-code but should use appropriate semaphore functions when necessary.

Void customer () {

If ( _____________) //Check if seat available

get_haircut (); //actual work of getting haircut

}

Else{

}

}

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

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions