BEST代写-线上留学生作业代写 & 论文代写专家

成立于2015年的老牌留学生代写品牌-BEST代写提供超过百门冷热门留学学科的作业和论文代写服务。全网BEST原创,高质,准时的留学生代写。

操作系统代写 | 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

评论已关闭。