subject

N customers enter the bakery to buy cookies. Each customer gets its turn[i], by computing a next number, and waits to be served. The clerk uses a counter to keep track of the served customers The clerk serves the customer whose turn[i] is equal to the counter. After each serve ( ),the clerk increments the counter. When the counter reaches N, the clerk considers that it is done and leaves for home.

(Shared variables)
turn[i] = 0 i = I, , N (N s initialized to 10)
number=0;
served [i]=0;
counter=0;
customer i( ){
number++;
turn[i]- number;
while (!served[i]) { };
getServed( );
go home;
}

clerk () {
while (counter < N) {
counter++;
for( int j=1 ; j<-N; j++) {
if (counterturn[j]) {
servedj[] = True;
serve( ); // simulated by sleep
served[j]=False; //if
}// for
}// while
leave;
} // clerk

All customer( ) and clerk( ) processes execute concurrently.
(a) Is it possible for two customers to compute the same number? Explain. If yes, give the execution sequence that will show it.
(b) Under the hypothesis that each customer has computed a different number value, is it possible for customers to compete for the same cookies (because their turn[i] is the same)? Explain. If yes, give the execution sequence that will show it.
(c) Under the hypothesis that all customers have their turn[i] set before the clerk starts executing, is it possible for a customer to starve (busy wait forever)? Explain. If yes, give the execution sequence that will show it.
(d) Is it possible for the clerk to never go home? Explain. If yes, give the execution sequence that will show it.
(e) If there are N cookies on the shelf, is it possible for the clerk to run out of cookies before all the customers got served? Explain. If yes, give the execution sequence that will show it.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 04:00
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
Answers: 3
question
Computers and Technology, 23.06.2019 13:30
What is the primary difference between the header section of a document and the body? a. the body is displayed on the webpage and the header is not. b. the header is displayed on the webpage and the body is not. c. the tag for the body is self-closing, but the tags for the headers must be closed. d. the tag for the header is self closing, but the tag for the body must be closed.
Answers: 3
question
Computers and Technology, 24.06.2019 08:30
Aconsumer would pay an extra they used the rent to own program to buy the computer, rather than using cash. for all of the items, is the cheapest option over the life of the contract. the most expensive overall option is to use purchase the item.
Answers: 2
question
Computers and Technology, 24.06.2019 21:00
When replacing a thermostat or water pump, coolant drained from the cooling system should be
Answers: 1
You know the right answer?
N customers enter the bakery to buy cookies. Each customer gets its turn[i], by computing a next num...
Questions
question
Social Studies, 09.09.2019 03:20
question
Mathematics, 09.09.2019 03:20
question
Chemistry, 09.09.2019 03:20