Question

In: Computer Science

bakery algorithm

Now consider a version of the bakery algorithm without the variable choosing. Then we have
1 int number[n];
2 while (true) {
3 number[i] = 1 + getmax(number[], n);
4 for (int j = 0; j < n; j++){
5 while ((number[j]! = 0) && (number[j],j) < (number[i],i)) { };
6 }
7 /* critical section */;
8 number [i] = 0;
9 /* remainder */;
10 }
Does this version violate mutual exclusion? Explain why or why not.

Solutions

Expert Solution

Suppose we have two processes just beginning; call them p0 and p1. Both reach line 3 at the same time. Now, we'll assume both read number[0] and number[1] before either addition takes place. Let p1 complete the line, assigning 1 to number[1], but p0 block before the assignment. Then p1 gets through the while loop at line 5 and enters the critical section. While in the critical section, it blocks; p0 unblocks, and assigns 1 to number[0] at line 3. It proceeds to the while loop at line 5. When it goes through that loop for j = 1, the first condition on line 5 is true. Further, the second condition on line 5 is false, so p0 enters the critical section. Now p0 and p1 are both in the critical section, violating mutual exclusion. The reason for choosing is to prevent the while loop in line 5 from being entered when process j is setting its number[j]. Note that if the loop is entered and then process j reaches line 3, one of two situations arises. Either number[j] has the value 0 when the first test is executed, in which case process i moves on to the next process, or number[j] has a non-zero value, in which case at some point number[j] will be greater than number[i] (since process i finished executing statement 3 before process j began). Either way, process i will enter the critical section before process j, and when process j reaches the while loop, it will loop at least until process i leaves the critical section.


Either way, process i will enter the critical section before process j, and when process j reaches the while loop, it will loop at least until process i leaves the critical section.

Related Solutions

A bakery makes Jumbo biscuits and Regular biscuits. The bakery is limited to: a. The oven...
A bakery makes Jumbo biscuits and Regular biscuits. The bakery is limited to: a. The oven can bake at most 150 biscuits per day. b. Each jumbo biscuit requires 2oz of flour and each regular biscuit requires 1oz of flour. The bakery has 200oz of flour available per day. c. Due to cooking time constraints, the total number of regular biscuits cannot exceed 130 d. Due to cooking time constraints, the total number of jumbo biscuits cannot exceed 70. The...
What s bakery output? What goals determine bakery output?
What s bakery output? What goals determine bakery output? 
The output of a bakery depends on the number of bakers employed. The bakery sells its...
The output of a bakery depends on the number of bakers employed. The bakery sells its good in a competitive product market at a price of P = $2. The daily wage of bakers is W = $50. a) Fill in all of the blanks in the table below. Show all of your work! (Hint: notice that the number of bakers increases by increments of 2.) Bakers Output (units per day) Marginal Product Total Revenue Marginal Revenue Product Value of...
There is a well-known bakery in the town, named Paris Bakery A). what is the daily...
There is a well-known bakery in the town, named Paris Bakery A). what is the daily revenue of the bakery based on the following assumptions? (10 points) - there are 10 customers in/out in 10 minutes -each costumer buys 3 biscuits on average -The price of biscuit is $1.50 each -The bakery open from 8 A.M to 6 P.M B) Owner of the Bakery wants to adopt Kanban system to reduce the inventory. Howmany Kanban containers will be needed to...
A bakery is considering buying one of two gas ovens. The bakery requires that the temperature...
A bakery is considering buying one of two gas ovens. The bakery requires that the temperature remain constant during a baking operation. A study was conducted to measure the variance in temperature of the ovens during the baking process. The variance in temperature before the thermostat restarted the flame for the Monarch oven was 2 for 21 measurements. The variance for the Kraft oven was 3.1 for 18 measurements. Does this information provide sufficient reason to conclude that there is...
1. Mkt. for bakery workers. A binding minimum wage is imposed in the market for bakery...
1. Mkt. for bakery workers. A binding minimum wage is imposed in the market for bakery workers. Show the minimum wage Wmin, the number of workers who will have jobs at the new minimum wage Emin, and the Surplus (Su) or shortage (Sh), the total surplus (TS), the deadweight loss (DWL). 2. Mkt. for hand‐made bagels. The change in labor market for bakery workers affects supply/demand of bagels because ____________ _________________________.   Show the effect of the change workers’ wages. Equilibrium...
Alex owns and operates a bakery. The bakery sells 3,000 cookies per month at a price...
Alex owns and operates a bakery. The bakery sells 3,000 cookies per month at a price of $2 each and 400 cakes per month at a price of $10 each. It costs Alex $1,500 per month to rent the space in which their bakery operates, $500 per month for utilities and $2,000 per month for the baking ingredients they use to make the cookies. Alex's previous job as a baker for a large restaurant paid an income of $3,000 per...
A bakery must decide how many pies to prepare for the upcoming weekend. The bakery has...
A bakery must decide how many pies to prepare for the upcoming weekend. The bakery has the option to make 50, 100, or 150 pies. Assume that demand for the pies can be 50, 100, or 150. Each pie costs $5 to make and sells for $7. Unsold pies are donated to a nearby charity center. Assume that there is no opportunity cost for lost sales. 7) Refer to the information above. a. Which alternative should be chosen based on...
mutual exclusion is Lamport’s bakery
A software approach to mutual exclusion is Lamport’s bakery algorithm [LAMP74], so called because it is based on the practice in bakeries and other shops in which every customer receives a numbered ticket on arrival, allowing each to be served in turn. The algorithm is as follows:boolean choosing[n];int number[n];while (true) {choosing[i] = true;number[i] = 1 + getmax(number[], n);choosing[i] = false;for (int j = 0; j < n; j++){while (choosing[j]) { };while ((number[j] != 0) && (number[j],j) < (number[i],i)) { };}/*...
Bakery A sells bread for $2 per loaf that costs $0.80 per loaf to make. Bakery...
Bakery A sells bread for $2 per loaf that costs $0.80 per loaf to make. Bakery A gives a 75% discount for its bread at the end of the day. Demand for the bread is normally distributed with a mean of 300 and a standard deviation of 30. What order quantity maximizes expected profit for Bakery A? a) 324.00 b) 300.17 c) 325.25
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT