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 = 1, ..., N (N is 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 (counter == turn[j]){served[j] = True; serve();//simulated by sleep served[j] = 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: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 23.06.2019 00:10
Write a function so that the main0 code below can be replaced by the simpler code that calls function mphandminutes tomiles0. original main0 int main) l double milesperhour-70.0; double minutestraveled = 100.0; double hourstraveled; double milestraveled; hourstraveled = minutestraveled / 60.0; milestraveled = hourstraveled * milesperhour; cout < "miles" 2 using namespace std; 4 /* your solution goes here/ 6 int maino 1 test passed 7 double milesperhour 70.0 all tests passed 8 double minutestraveled 100.0; 10 cout < < "miles: " < < mphandminutestomiles(milesper-hour, minutestraveled) < < endl; 12 return 0; 13
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
Experimental data that is expressed using numbers is said to be
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
How can a user delete a drawing object
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
History, 19.02.2020 02:55
question
Mathematics, 19.02.2020 02:55
question
Mathematics, 19.02.2020 02:56
Questions on the website: 13722360