Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

******PLEASE EXPLAIN HOW YOU GOT THE ANSWER, because i have my own answers to compare it too and how you obtained your answer. Operating System

******PLEASE EXPLAIN HOW YOU GOT THE ANSWER, because i have my own answers to compare it too and how you obtained your answer.

Operating System Concurrent processes PROBLEM SAMPLE 2 Q5 (18 points)

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.

* Initial condition: (Shared variables)

turn[i] = 0 i = 1, .. , N (N is initialized to 10); number= 0; served[i]=0; counter = 0;

* Customer program

customer() { number++; turn[i]=number; while(!server[i]) { busyWait }; getServed(); go home; }

* Clerk program

clerk() { while (counter < N) { counter++; for(int j=1;j<=N;j++) { if(counter==turn[j]) { served[j]==True; serve(); served[j]=False; }//false }//forloop }//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.

Reformat based on expert feedback.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions