BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

操作系统代写 | CS 3800 Operating Systems HW #3

操作系统代写 | CS 3800 Operating Systems HW #3

本次美国代写是操作系统的一个Homework

For this assignment, you are to walk through the sleeping barber problem and fill in the values of each semaphore and queue at every step of the problem. Also, answer all the questions at the end of this document.

Code for our sleeping barbers problem appears below.

//A variant of the Sleeping Barber Problem using 1 binary semaphore and 2 general semaphores

// background details https://en.wikipedia.org/wiki/Sleeping_barber_problem

 

binary_semaphore AccessToWaitingRoomSeats=1;

general_semaphore BarberReady=0, CustomerReady=0;

int numberOfFreeWaitingRoomSeats;

 

void Barber() {

while (true)        {

semWait(CustomerReady);

semWaitB(AccessToWaitingRoomSeats);

numberOfFreeWaitingRoomSeats += 1;

semSignal(BarberReady);

semSignalB(AccessToWaitingRoomSeats);

CutHair();

}

}

 

void Customer() {

semWaitB(AccessToWaitingRoomSeats);

if(numberOfFreeWaitingRoomSeats>0)

{

numberOfFreeWaitingRoomSeats = 1;

semSignal(CustomerReady);

semSignalB(AccessToWaitingRoomSeats);

semWait(BarberReady);

GetHairCut();

}

else

{  //no space, must leave!

semSignalB(AccessToWaitingRoomSeats);

}

}

 

void main()

{

numberOfFreeWaitingRoomSeats=2;

parbegin(barber, barber, customer, customer, customer, customer);

}

Sleeping Barber Questions:

  1. How many people / processes were involved with the barbershop? (5 pts)
  2. How many people were completely done getting a haircut at the end of the code step-through? (5 pts)
  3. How many people were still waiting to get their haircut? (5pts)
  4. How many people walked out? Why? (10pts)
bestdaixie

评论已关闭。