Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

N customers enter the bakery to buy cookies. Each customer gets its turn[i], by

ID: 3736491 • Letter: N

Question

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)i number++ turn[i]- number; while (!served[i); getServed); clerk ()l while (counter

Explanation / Answer

Question a

It is not possible for two customers to have the same number.As the counter is maintined by the clerk so when one customer comes its given a particular number and the other cutomers get the next numbers in the sequence.So it is not possible for two customers to have the same number.

Question b

Yeah it is possible for the customer who has computed a different number value is competing of the same cookies because their turn[i] is same.So lets take there is one customer only so its only one turn .And the next customer comes.Both are ordering in the same cookies.So now as there are no one so both these customer is wating for the same turn value.In this case it will be served using the first come first serve basis.

Question c

Yes it is possible that all customers have their turn[i] set before the clerk starts executing,and the customer is to starve(busy wait forever).Lets say the cookies are the most saled item.Everyday they are having 100 cookies.And the customer is lined around 300.So there are 300 customers but only 100 cookies then the rest of 200 customer will starve as the item has already finished but the customer are having the respective turn number

Question d

No it is not possible for the clerk to never go home.As with sometime the counter will reach the value N.Assuming we are having a certain number of customer daily.