1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gtnhenbr [62]
3 years ago
15

The Sleeping-Barber Problem:

Computers and Technology
1 answer:
s2008m [1.1K]3 years ago
6 0

Answer:

Explanation:

Following are the Semaphores:

Customers: Counts waiting customers;

Barbers: Number of idle barbers (0 or 1)

mutex: Used for mutual exclusion.

Cutting: Ensures that the barber won’t cut another customer’s hair before the previous customer leaves

Shared data variable:

count_cust: Counts waiting customers. ------------copy of customers. As value of semaphores can’t access directly.

// shared data

semaphore customers = 0; semaphore barbers = 0; semaphore cutting = 0; semaphore mutex = 1;

int count_cust= 0;

void barber() {

while(true) { //shop is always open

wait(customers); //sleep when there are no waiting customers

wait(mutex); //mutex for accessing customers1

count_cust= count_cust-1; //customer left

signal(barbers);

signal(mutex);

cut_hair();

}

}

void customer() {

wait(mutex); //mutex for accessing count_cust

if (count_cust< n) {

count_cust= count_cust+1; //new customer

signal(customers); signal(mutex);

wait(barbers); //wait for available barbers get_haircut();

}

else { //do nothing (leave) when all chairs are used. signal(mutex);

}

}

cut_hair(){ waiting(cutting);

}

get_haircut(){

get hair cut for some time; signal(cutting);

}

You might be interested in
The average pH of citrus fruits is 2.2, and this value has been stored in the variable avg_citrus_pH . Provide a statement to di
olasank [31]

Answer:

The statement in Python is:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

Explanation:

The programming language is not stated; so, I answered the question in 3 languages (Python, Java and C++)

Assume that avg_citrus_pH has been declared and initialized; all you need to do is invoke a print statement and then append the variable

In Python, use print()

In c++, use cout<<

In Java, use System.out.print()

So, the statements are:

Python:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

8 0
2 years ago
Which of the following is necessary for opening email attachments under most circumstances? The correct RAM The correct drivers
svet-max [94.6K]

Answer:

The Correct Software

Explanation:

Some mail application have built in support to view the attachment like in a phone. While others don't, so if that is the case your device will attempt to open the file according to its extension (.exe, .txt, .js etc.) If your device doesn't have the correct software to open it, then the other things don't matter.

4 0
3 years ago
WILL GIVE BRAINLIST IF ANSWERED RIGHT 1. An engine's _______ contains the cylinder block, the cylinders, the piston, the connect
miss Akunina [59]
First three are c b and d
3 0
2 years ago
Read 2 more answers
When designing a slide for presentation, it is best to include as much information as possible on every slide. True Or False
Mariulka [41]

Answer:

false

Explanation:

try to limit the amount of info on each slide

4 0
3 years ago
Read 2 more answers
What is a possible explanation for the issue described below? A user reports that ever since she or he began creating animations
Marat540 [252]
VRAM because VRAM is used for graphic intensive workloads
8 0
3 years ago
Read 2 more answers
Other questions:
  • An undesirable jagged appearance is referred to as
    7·2 answers
  • What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal() {
    5·1 answer
  • Which industry has the highest employment figure for both teen and young adults in July, 2014?
    6·1 answer
  • If two hosts are connected by five networks, how many frames will there be when one host sends a packet to the other host? 1 2 5
    13·1 answer
  • What does the binary odometer show about representing large numbers​
    15·1 answer
  • What is a system unit
    7·1 answer
  • What are some characteristics of filtering junk email in Outlook 2016? Check all that apply.
    10·2 answers
  • Vendors who use open source as part of their product offerings can expect to bring new products to the market faster because: Gr
    11·1 answer
  • Compare and contrast the leadership and leadership and management style of apple and Samsung ​
    6·1 answer
  • Distributed databases and data warehouses would be considered which data model type?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!